Skip to content

Commit

Permalink
Avoid illegal longjump() call (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
saitoha committed Dec 26, 2019
1 parent 52fc816 commit c1ef812
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
11 changes: 4 additions & 7 deletions Makefile.in
Expand Up @@ -192,8 +192,8 @@ CTAGS = ctags
CSCOPE = cscope
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \
$(srcdir)/libsixel.pc.in $(srcdir)/package.json.in.in \
ChangeLog NEWS compile config.guess config.sub depcomp \
install-sh ltmain.sh missing py-compile
ChangeLog NEWS compile config.guess config.sub install-sh \
ltmain.sh missing py-compile
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
Expand Down Expand Up @@ -930,13 +930,10 @@ valgrind: all
grep "indirectly lost: 0 bytes in 0 blocks" valgrind.log

coveralls:
coveralls -e sixel_orig -e include -e m4 \
-e stb_image.h -e stb_image_write.h
coveralls -e config.h -e stb_image.h -e stb_image_write.h -e examples -e include -e perl -e php -e ruby -e wic

coveralls-dryrun: test
coveralls -e sixel_orig -e include -e m4 \
-e stb_image.h -e stb_image_write.h \
--dryrun
coveralls -e config.h -e stb_image.h -e stb_image_write.h -e examples -e include -e perl -e php -e ruby -e wic --dryrun

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Expand Up @@ -159,6 +159,9 @@
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H

/* Define to 1 if you have the `longjmp' function. */
#undef HAVE_LONGJMP

/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
Expand Down
1 change: 1 addition & 0 deletions configure
Expand Up @@ -14001,6 +14001,7 @@ for ac_func in memcpy \
clearerr \
stat \
setjmp \
longjmp \
strerror \
isatty \
strncmp \
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -282,6 +282,7 @@ AC_CHECK_FUNCS([memcpy \
clearerr \
stat \
setjmp \
longjmp \
strerror \
isatty \
strncmp \
Expand Down
23 changes: 19 additions & 4 deletions src/loader.c
Expand Up @@ -268,13 +268,18 @@ read_palette(png_structp png_ptr,
}
}

jmp_buf jmpbuf;

/* libpng error handler */
static void
png_error_callback(png_structp png_ptr, png_const_charp error_message)
{
(void) png_ptr;

sixel_helper_set_additional_message(error_message);
longjmp(png_jmpbuf(png_ptr), (-1));
#if HAVE_SETJMP && HAVE_LONGJMP
longjmp(jmpbuf, 1);
#endif /* HAVE_SETJMP && HAVE_LONGJMP */
}


Expand Down Expand Up @@ -309,14 +314,14 @@ load_png(unsigned char /* out */ **result,
int i;
int depth;

#if USE_SETJMP && HAVE_SETJMP
if (setjmp(png_jmpbuf(png_ptr)) != 0) {
#if HAVE_SETJMP && HAVE_LONGJMP
if (setjmp(jmpbuf) != 0) {
sixel_allocator_free(allocator, *result);
*result = NULL;
status = SIXEL_PNG_ERROR;
goto cleanup;
}
#endif /* HAVE_SETJMP */
#endif /* HAVE_SETJMP && HAVE_LONGJMP */

status = SIXEL_FALSE;
rows = NULL;
Expand All @@ -330,6 +335,16 @@ load_png(unsigned char /* out */ **result,
status = SIXEL_PNG_ERROR;
goto cleanup;
}

#if HAVE_SETJMP
if (setjmp(png_jmpbuf(png_ptr)) != 0) {
sixel_allocator_free(allocator, *result);
*result = NULL;
status = SIXEL_PNG_ERROR;
goto cleanup;
}
#endif /* HAVE_SETJMP */

info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
sixel_helper_set_additional_message(
Expand Down

0 comments on commit c1ef812

Please sign in to comment.