Blame SOURCES/0001-Fixing-covscan-issues.patch

e3af14
diff -up cups-filters-1.0.35/utils/cups-browsed.c.covscan cups-filters-1.0.35/utils/cups-browsed.c
e3af14
--- cups-filters-1.0.35/utils/cups-browsed.c.covscan	2019-02-27 17:52:37.000000000 +0100
e3af14
+++ cups-filters-1.0.35/utils/cups-browsed.c	2019-03-18 16:01:49.345858931 +0100
e3af14
@@ -1934,7 +1934,10 @@ is_disabled(const char *printer, const c
e3af14
 	  pstate = (ipp_pstate_t)ippGetInteger(attr, 0);
e3af14
 	else if (!strcmp(ippGetName(attr), "printer-state-message") &&
e3af14
 		 ippGetValueTag(attr) == IPP_TAG_TEXT) {
e3af14
-	  free(pstatemsg);
e3af14
+	  if (pstatemsg != NULL) {
e3af14
+	    free(pstatemsg);
e3af14
+	    pstatemsg = NULL;
e3af14
+	  }
e3af14
 	  p = ippGetString(attr, 0, NULL);
e3af14
 	  if (p != NULL) pstatemsg = strdup(p);
e3af14
 	}
e3af14
@@ -1951,16 +1954,22 @@ is_disabled(const char *printer, const c
e3af14
 	case IPP_PRINTER_IDLE:
e3af14
 	case IPP_PRINTER_PROCESSING:
e3af14
 	  ippDelete(response);
e3af14
-	  free(pstatemsg);
e3af14
+	  if (pstatemsg != NULL) {
e3af14
+	    free(pstatemsg);
e3af14
+	    pstatemsg = NULL;
e3af14
+	  }
e3af14
 	  return NULL;
e3af14
 	case IPP_PRINTER_STOPPED:
e3af14
 	  ippDelete(response);
e3af14
 	  if (reason == NULL)
e3af14
 	    return pstatemsg;
e3af14
-	  else if (strcasestr(pstatemsg, reason) != NULL)
e3af14
+	  else if (pstatemsg != NULL && (strcasestr(pstatemsg, reason) != NULL))
e3af14
 	    return pstatemsg;
e3af14
 	  else {
e3af14
-	    free(pstatemsg);
e3af14
+            if (pstatemsg != NULL) {
e3af14
+                free(pstatemsg);
e3af14
+                pstatemsg = NULL;
e3af14
+            }
e3af14
 	    return NULL;
e3af14
 	  }
e3af14
 	}
e3af14
@@ -1969,12 +1978,18 @@ is_disabled(const char *printer, const c
e3af14
     debug_printf("No information regarding enabled/disabled found about the requested printer '%s'\n",
e3af14
 		 printer);
e3af14
     ippDelete(response);
e3af14
-    free(pstatemsg);
e3af14
+    if (pstatemsg != NULL) {
e3af14
+      free(pstatemsg);
e3af14
+      pstatemsg = NULL;
e3af14
+    }
e3af14
     return NULL;
e3af14
   }
e3af14
   debug_printf("ERROR: Request for printer info failed: %s\n",
e3af14
 	       cupsLastErrorString());
e3af14
-  free(pstatemsg);
e3af14
+  if (pstatemsg != NULL) {
e3af14
+    free(pstatemsg);
e3af14
+    pstatemsg = NULL;
e3af14
+  }
e3af14
   return NULL;
e3af14
 }
e3af14
 
e3af14
@@ -3421,6 +3436,8 @@ gboolean handle_cups_queues(gpointer unu
e3af14
       } else {
e3af14
 	/* Device URI: ipp(s)://<remote host>:631/printers/<remote queue> */
e3af14
 	strncpy(device_uri, p->uri, sizeof(device_uri));
e3af14
+	if (strlen(p->uri) > HTTP_MAX_URI-1)
e3af14
+	  device_uri[HTTP_MAX_URI-1] = '\0';
e3af14
 	debug_printf("Print queue %s is for an IPP network printer, or we do not get notifications from CUPS, using direct device URI %s\n",
e3af14
 		     p->name, device_uri);
e3af14
       }
e3af14
@@ -3529,6 +3546,8 @@ gboolean handle_cups_queues(gpointer unu
e3af14
 	  } else if (!strncmp(line, "*Default", 8)) {
e3af14
 	    cont_line_read = 0;
e3af14
 	    strncpy(keyword, line + 8, sizeof(keyword));
e3af14
+	    if ((strlen(line) + 8) > 1023)
e3af14
+	      keyword[1023] = '\0';
e3af14
 	    for (keyptr = keyword; *keyptr; keyptr ++)
e3af14
 	      if (*keyptr == ':' || isspace(*keyptr & 255))
e3af14
 		break;
e3af14
@@ -5871,7 +5890,7 @@ read_configuration (const char *filename
e3af14
      in the configuration file is used. */
e3af14
   while ((i < cupsArrayCount(command_line_config) &&
e3af14
 	  (value = cupsArrayIndex(command_line_config, i++)) &&
e3af14
-	  strncpy(line, value, sizeof(line))) ||
e3af14
+	  strncpy(line, value, sizeof(line)) && ((strlen(value) > HTTP_MAX_BUFFER-1)? line[HTTP_MAX_BUFFER-1] = '\0':  1)) ||
e3af14
 	 cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) {
e3af14
     if (linenum < 0) {
e3af14
       /* We are still reading options from the command line ("-o ..."),
e3af14
@@ -6098,6 +6117,7 @@ read_configuration (const char *filename
e3af14
 	if (filter->cregexp)
e3af14
 	  regfree(filter->cregexp);
e3af14
 	free(filter);
e3af14
+	filter = NULL;
e3af14
       }
e3af14
     } else if ((!strcasecmp(line, "BrowseInterval") || !strcasecmp(line, "BrowseTimeout")) && value) {
e3af14
       int t = atoi(value);
e3af14
@@ -6113,7 +6133,7 @@ read_configuration (const char *filename
e3af14
 	debug_printf("Invalid %s value: %d\n",
e3af14
 		     line, t);
e3af14
     } else if (!strcasecmp(line, "DomainSocket") && value) {
e3af14
-      if (value[0] != '\0')
e3af14
+      if (DomainSocket == NULL && value[0] != '\0')
e3af14
 	DomainSocket = strdup(value);
e3af14
     } else if ((!strcasecmp(line, "HttpLocalTimeout") || !strcasecmp(line, "HttpRemoteTimeout")) && value) {
e3af14
       int t = atoi(value);
e3af14
@@ -6168,7 +6188,7 @@ read_configuration (const char *filename
e3af14
       else if (!strncasecmp(value, "QueueOnServers", 14))
e3af14
 	LoadBalancingType = QUEUE_ON_SERVERS;
e3af14
     } else if (!strcasecmp(line, "DefaultOptions") && value) {
e3af14
-      if (strlen(value) > 0)
e3af14
+      if (DefaultOptions == NULL && strlen(value) > 0)
e3af14
 	DefaultOptions = strdup(value);
e3af14
     } else if (!strcasecmp(line, "AutoShutdown") && value) {
e3af14
       char *p, *saveptr;
e3af14
@@ -6537,6 +6557,8 @@ int main(int argc, char*argv[]) {
e3af14
      daemon, not with remote ones. */
e3af14
   if (getenv("CUPS_SERVER") != NULL) {
e3af14
     strncpy(local_server_str, getenv("CUPS_SERVER"), sizeof(local_server_str));
e3af14
+    if (strlen(getenv("CUPS_SERVER")) > 1023)
e3af14
+      local_server_str[1023] = '\0';
e3af14
   } else {
e3af14
 #ifdef CUPS_DEFAULT_DOMAINSOCKET
e3af14
     if (DomainSocket == NULL)
e3af14
@@ -6876,6 +6898,11 @@ fail:
e3af14
   /* Close log file if we have one */
e3af14
   if (debug_logfile == 1)
e3af14
     stop_debug_logging();
e3af14
+  
e3af14
+  if (DefaultOptions != NULL)
e3af14
+    free(DefaultOptions);
e3af14
+  if (DomainSocket != NULL)
e3af14
+    free(DomainSocket);
e3af14
 
e3af14
   return ret;
e3af14