Compare commits

...

8 Commits
1 ... master

Author SHA1 Message Date
Tom Schwindl
882d54c225 remove unnecessary NULL checks and add void for an empty parameter list 2023-01-10 18:55:47 +01:00
Hiltjo Posthuma
08006e0d00 sent.1: fix some mandoc warnings 2023-01-09 18:27:22 +01:00
Hiltjo Posthuma
3f107fcf72 Makefile: be verbose 2023-01-09 18:27:12 +01:00
Augusto Castelo
c271dfb848 free XImage before creating a new one
ffprepare was allocating a new XImage but wasn't freeing the
previously allocated one
2023-01-09 18:22:20 +01:00
Chris Down
2649e8d533 Avoid out-of-bounds access when a slide input line begins with \0
If we read in a line with \0 at the beginning, blen will be 0. However,
we then try to index our copy of the buffer with
s->lines[s->linecount][blen-1], we'll read (and potentially write if the
data happens to be 0x0A) outside of strdup's allocated memory, and may
crash.

Fix this by just rejecting lines with a leading \0. Lines with nulls
embedded in other places don't invoke similar behaviour, since the
length is still >0.
2020-05-14 11:43:34 +02:00
Markus Teich
72d33d463f update license 2017-09-07 23:40:26 +02:00
Laslo Hunhold
a5f760fa0e Correctly handle files that contain no slides
Otherwise, on reloading sent would segfault. Move the check-logic to
load() rather than doing it in main() to prevent other misuses of it in
the future.
2017-09-07 23:37:00 +02:00
Markus Teich
53541ee1bd update license 2017-09-04 00:23:09 +02:00
4 changed files with 66 additions and 64 deletions

25
LICENSE
View File

@ -1,6 +1,6 @@
ISC-License ISC-License
(c) 2014-2016 Markus Teich <markus.teich@stusta.mhn.de> (c) 2014-2017 Markus Teich <markus.teich@stusta.mhn.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -14,15 +14,16 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
(c) 2015 Jonas Jelten <jj@sft.mx> (c) 2016,2017 Laslo Hunhold <dev@frign.de>
(c) 2015 Szabolcs Nagy <nsz@port70.net> (c) 2016 ssd <ssd@mailless.org>
(c) 2015 Tony Lainson <t.lainson@gmail.com>
(c) 2015 Jan Christoph Ebersbach <jceb@e-jc.de>
(c) 2015 Ivan Tham <pickfire@riseup.net>
(c) 2015 Quentin Rameau <quinq@fifth.space>
(c) 2015 Alexis <surryhill@gmail.com>
(c) 2015 Dimitris Papastamos <sin@2f30.org>
(c) 2015 Grant Mathews <grant.m.mathews@gmail.com>
(c) 2015 David Phillips <dbphillipsnz@gmail.com>
(c) 2016 Laslo Hunhold <dev@frign.de>
(c) 2016 Hiltjo Posthuma <hiltjo@codemadness.org> (c) 2016 Hiltjo Posthuma <hiltjo@codemadness.org>
(c) 2015 David Phillips <dbphillipsnz@gmail.com>
(c) 2015 Grant Mathews <grant.m.mathews@gmail.com>
(c) 2015 Dimitris Papastamos <sin@2f30.org>
(c) 2015 Alexis <surryhill@gmail.com>
(c) 2015 Quentin Rameau <quinq@fifth.space>
(c) 2015 Ivan Tham <pickfire@riseup.net>
(c) 2015 Jan Christoph Ebersbach <jceb@e-jc.de>
(c) 2015 Tony Lainson <t.lainson@gmail.com>
(c) 2015 Szabolcs Nagy <nsz@port70.net>
(c) 2015 Jonas Jelten <jj@sft.mx>

View File

@ -18,43 +18,35 @@ config.h:
cp config.def.h config.h cp config.def.h config.h
.c.o: .c.o:
@echo CC $< ${CC} -c ${CFLAGS} $<
@${CC} -c ${CFLAGS} $<
${OBJ}: config.h config.mk ${OBJ}: config.h config.mk
sent: ${OBJ} sent: ${OBJ}
@echo CC -o $@ ${CC} -o $@ ${OBJ} ${LDFLAGS}
@${CC} -o $@ ${OBJ} ${LDFLAGS}
cscope: ${SRC} config.h cscope: ${SRC} config.h
@echo cScope cscope -R -b || echo cScope not installed
@cscope -R -b || echo cScope not installed
clean: clean:
@echo cleaning rm -f sent ${OBJ} sent-${VERSION}.tar.gz
@rm -f sent ${OBJ} sent-${VERSION}.tar.gz
dist: clean dist: clean
@echo creating dist tarball mkdir -p sent-${VERSION}
@mkdir -p sent-${VERSION} cp -R LICENSE Makefile config.mk config.def.h ${SRC} sent-${VERSION}
@cp -R LICENSE Makefile config.mk config.def.h ${SRC} sent-${VERSION} tar -cf sent-${VERSION}.tar sent-${VERSION}
@tar -cf sent-${VERSION}.tar sent-${VERSION} gzip sent-${VERSION}.tar
@gzip sent-${VERSION}.tar rm -rf sent-${VERSION}
@rm -rf sent-${VERSION}
install: all install: all
@echo installing executable file to ${DESTDIR}${PREFIX}/bin mkdir -p ${DESTDIR}${PREFIX}/bin
@mkdir -p ${DESTDIR}${PREFIX}/bin cp -f sent ${DESTDIR}${PREFIX}/bin
@cp -f sent ${DESTDIR}${PREFIX}/bin chmod 755 ${DESTDIR}${PREFIX}/bin/sent
@chmod 755 ${DESTDIR}${PREFIX}/bin/sent mkdir -p ${DESTDIR}${MANPREFIX}/man1
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 cp sent.1 ${DESTDIR}${MANPREFIX}/man1/sent.1
@mkdir -p ${DESTDIR}${MANPREFIX}/man1 chmod 644 ${DESTDIR}${MANPREFIX}/man1/sent.1
@cp sent.1 ${DESTDIR}${MANPREFIX}/man1/sent.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/sent.1
uninstall: uninstall:
@echo removing executable file from ${DESTDIR}${PREFIX}/bin rm -f ${DESTDIR}${PREFIX}/bin/sent
@rm -f ${DESTDIR}${PREFIX}/bin/sent
.PHONY: all options clean dist install uninstall cscope .PHONY: all options clean dist install uninstall cscope

22
sent.1
View File

@ -1,5 +1,6 @@
.Dd 2016-08-12 .Dd August 12, 2016
.Dt SENT 1 .Dt SENT 1
.Os
.Sh NAME .Sh NAME
.Nm sent .Nm sent
.Nd simple plaintext presentation tool .Nd simple plaintext presentation tool
@ -10,13 +11,14 @@
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
is a simple plain text presentation tool for X. sent does not need LaTeX, is a simple plain text presentation tool for X. sent does not need LaTeX,
LibreOffice or any other fancy file format. Instead, sent reads plain text LibreOffice or any other fancy file format.
describing the slides. sent can also draw images. Instead, sent reads plain text describing the slides. sent can also draw
images.
.Pp .Pp
Every paragraph represents a slide in the presentation. Especially for Every paragraph represents a slide in the presentation.
presentations using the Takahashi method this is very nice and allows Especially for presentations using the Takahashi method this is very nice and
you to write the presentation for a quick lightning talk within a allows you to write the presentation for a quick lightning talk within a few
few minutes. minutes.
.Sh OPTIONS .Sh OPTIONS
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl v .It Fl v
@ -36,7 +38,8 @@ Go to previous slide, if existent.
.It Sy Escape | q .It Sy Escape | q
Quit. Quit.
.It Sy r .It Sy r
Reload the slides. Only works on file input. Reload the slides.
Only works on file input.
.It Sy Right | Return | Space | l | j | Down | Next | n .It Sy Right | Return | Space | l | j | Down | Next | n
Go to next slide, if existent. Go to next slide, if existent.
.It Sy Left | Backspace | h | k | Up | Prior | p .It Sy Left | Backspace | h | k | Up | Prior | p
@ -63,6 +66,7 @@ without interpreting them.
.Sh CUSTOMIZATION .Sh CUSTOMIZATION
.Nm .Nm
can be customized by creating a custom config.h and (re)compiling the can be customized by creating a custom config.h and (re)compiling the
source code. This keeps it fast, secure and simple. source code.
This keeps it fast, secure and simple.
.Sh SEE ALSO .Sh SEE ALSO
.Xr 2ff 1 .Xr 2ff 1

39
sent.c
View File

@ -99,12 +99,12 @@ static void load(FILE *fp);
static void advance(const Arg *arg); static void advance(const Arg *arg);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static void resize(int width, int height); static void resize(int width, int height);
static void run(); static void run(void);
static void usage(); static void usage(void);
static void xdraw(); static void xdraw(void);
static void xhints(); static void xhints(void);
static void xinit(); static void xinit(void);
static void xloadfonts(); static void xloadfonts(void);
static void bpress(XEvent *); static void bpress(XEvent *);
static void cmessage(XEvent *); static void cmessage(XEvent *);
@ -216,7 +216,6 @@ ffload(Slide *s)
s->img->bufwidth = ntohl(*(uint32_t *)&hdr[8]); s->img->bufwidth = ntohl(*(uint32_t *)&hdr[8]);
s->img->bufheight = ntohl(*(uint32_t *)&hdr[12]); s->img->bufheight = ntohl(*(uint32_t *)&hdr[12]);
if (s->img->buf)
free(s->img->buf); free(s->img->buf);
/* internally the image is stored in 888 format */ /* internally the image is stored in 888 format */
s->img->buf = ecalloc(s->img->bufwidth * s->img->bufheight, strlen("888")); s->img->buf = ecalloc(s->img->bufwidth * s->img->bufheight, strlen("888"));
@ -270,6 +269,9 @@ ffprepare(Image *img)
if (depth < 24) if (depth < 24)
die("sent: Display color depths < 24 not supported"); die("sent: Display color depths < 24 not supported");
if (img->ximg)
XDestroyImage(img->ximg);
if (!(img->ximg = XCreateImage(xw.dpy, CopyFromParent, depth, ZPixmap, 0, if (!(img->ximg = XCreateImage(xw.dpy, CopyFromParent, depth, ZPixmap, 0,
NULL, width, height, 32, 0))) NULL, width, height, 32, 0)))
die("sent: Unable to create XImage"); die("sent: Unable to create XImage");
@ -428,6 +430,10 @@ load(FILE *fp)
maxlines = 0; maxlines = 0;
memset((s = &slides[slidecount]), 0, sizeof(Slide)); memset((s = &slides[slidecount]), 0, sizeof(Slide));
do { do {
/* if there's a leading null, we can't do blen-1 */
if (buf[0] == '\0')
continue;
if (buf[0] == '#') if (buf[0] == '#')
continue; continue;
@ -457,6 +463,9 @@ load(FILE *fp)
if (!p) if (!p)
break; break;
} }
if (!slidecount)
die("sent: No slides in file");
} }
void void
@ -489,7 +498,7 @@ resize(int width, int height)
} }
void void
run() run(void)
{ {
XEvent ev; XEvent ev;
@ -511,7 +520,7 @@ run()
} }
void void
xdraw() xdraw(void)
{ {
unsigned int height, width, i; unsigned int height, width, i;
Image *im = slides[idx].img; Image *im = slides[idx].img;
@ -539,7 +548,7 @@ xdraw()
} }
void void
xhints() xhints(void)
{ {
XClassHint class = {.res_name = "sent", .res_class = "presenter"}; XClassHint class = {.res_name = "sent", .res_class = "presenter"};
XWMHints wm = {.flags = InputHint, .input = True}; XWMHints wm = {.flags = InputHint, .input = True};
@ -557,7 +566,7 @@ xhints()
} }
void void
xinit() xinit(void)
{ {
XTextProperty prop; XTextProperty prop;
unsigned int i; unsigned int i;
@ -601,7 +610,7 @@ xinit()
} }
void void
xloadfonts() xloadfonts(void)
{ {
int i, j; int i, j;
char *fstrs[LEN(fontfallbacks)]; char *fstrs[LEN(fontfallbacks)];
@ -620,7 +629,6 @@ xloadfonts()
} }
for (j = 0; j < LEN(fontfallbacks); j++) for (j = 0; j < LEN(fontfallbacks); j++)
if (fstrs[j])
free(fstrs[j]); free(fstrs[j]);
} }
@ -670,7 +678,7 @@ configure(XEvent *e)
} }
void void
usage() usage(void)
{ {
die("usage: %s [file]", argv0); die("usage: %s [file]", argv0);
} }
@ -695,9 +703,6 @@ main(int argc, char *argv[])
load(fp); load(fp);
fclose(fp); fclose(fp);
if (!slidecount)
usage();
xinit(); xinit();
run(); run();