Fix segmentation fault when libpaper is unconfigured When barcode is compiled with support for libpaper, but libpaper is not configured and papersize environment variables are not set, systempapername() returns NULL. This causes get_page_geometry() to crash subsequently. Source code for libpaper suggests that users are expected to call defaultpapername() and use its return value instead if that happens. Additionally, add a check that will only call get_page_geometry() with non-NULL values. Signed-off-by: Clemens Lang Upstream-Status: Submitted [http://lists.gnu.org/archive/html/bug-barcode/2015-12/msg00000.html] --- main.c.orig 2015-12-10 23:47:45.000000000 +0100 +++ main.c 2015-12-10 23:51:03.000000000 +0100 @@ -475,10 +475,18 @@ /* If no paper size has been specified, use the default, if any */ if (!page_name) { +#ifndef NO_LIBPAPER + const char *papername = systempapername(); /* or the system default */ + if (!papername) { + papername = defaultpapername(); + } +#endif page_wid = 595; page_hei = 842; page_name = "A4"; /* I live in Europe :) */ #ifndef NO_LIBPAPER - get_page_geometry(systempapername()); /* or the system default */ + if (papername) { + get_page_geometry(papername); + } #endif }