bug-barcode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-barcode] [PATCH] Avoid segfault on unconfigured libpaper


From: Clemens Lang
Subject: [Bug-barcode] [PATCH] Avoid segfault on unconfigured libpaper
Date: Fri, 11 Dec 2015 00:08:50 +0100
User-agent: Mutt/1.5.24 (2015-08-30)

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 <address@hidden>
--- 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
     }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]