Blob Blame History Raw
diff --git a/NEWS b/NEWS
index f4b774e..0b53aa8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
 1.5.13 changes
 --------------
+- add checks for NULL in udev-configure-printer (Fedora #1761097)
 
 1.5.12 changes
 --------------
diff --git a/udev/udev-configure-printer.c b/udev/udev-configure-printer.c
index 83092fc..8f6ce3d 100644
--- a/udev/udev-configure-printer.c
+++ b/udev/udev-configure-printer.c
@@ -1285,7 +1285,8 @@ normalize_device_uri(const char *str_orig)
 {
   int i, j;
   int havespace = 0;
-  char *str;
+  char *str = NULL;
+  char *cropped_str = NULL;
 
   if (str_orig == NULL)
     return NULL;
@@ -1333,7 +1334,11 @@ normalize_device_uri(const char *str_orig)
 	 (strstr(str, "packard ") == str) ||
 	 (strstr(str, "apollo ") == str) ||
 	 (strstr(str, "usb ") == str))
-    str = strchr(str, ' ') + 1;
+  {
+    cropped_str = strdup(strchr(str, ' ') + 1);
+    free(str);
+    str = cropped_str;
+  }
 
   return str;
 }
@@ -1411,7 +1416,7 @@ for_each_matching_queue (struct device_uris *device_uris,
       const char *printer_state_message = NULL;
       int state = 0;
       size_t i, l;
-      char *this_device_uri_n, *device_uri_n;
+      char *this_device_uri_n = NULL, *device_uri_n = NULL;
       const char *ps1, *ps2, *pi1, *pi2;
 
       while (attr && ippGetGroupTag (attr) != IPP_TAG_PRINTER)
@@ -1507,13 +1512,21 @@ for_each_matching_queue (struct device_uris *device_uris,
 		  break;
 		}
 	    }
+            if (device_uri_n != NULL)
+            {
+              free(device_uri_n);
+              device_uri_n = NULL;
+            }
 	}
 
       firstqueue = 0;
 
     skip:
-      free(device_uri_n);
-      free(this_device_uri_n);
+      if (this_device_uri_n != NULL)
+      {
+        free(this_device_uri_n);
+        this_device_uri_n = NULL;
+      }
       if (!attr)
 	break;
     }