]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
Fix coverity issue 7.
authorZdenek Dohnal <zdohnal@redhat.com>
Wed, 15 Feb 2023 18:03:37 +0000 (19:03 +0100)
committerZdenek Dohnal <zdohnal@redhat.com>
Wed, 15 Feb 2023 18:03:37 +0000 (19:03 +0100)
Alloc the array only in case we need it to prevent overwriting pointer

utils/driverless.c

index 8af843333df693dd4111ccbe5c016290a8d5d0a6..7c67cbe19dce36a02b3101082fe22eb5dd488ca6 100644 (file)
@@ -495,19 +495,20 @@ list_printers (int mode, int reg_type_no, int isFax)
   if (fp) {
     while ((bytes = cupsFileGetLine(fp, buffer, sizeof(buffer))) > 0 ||
           (bytes < 0 && (errno == EAGAIN || errno == EINTR))) {
-      ippfind_output = (char *)malloc(MAX_OUTPUT_LEN*(sizeof(char)));
       ptr = buffer;
       while (ptr && !isalnum(*ptr & 255)) ptr ++;
       if ((!strncasecmp(ptr, "ipps", 4) && ptr[4] == '\t')) {
        ptr += 4;
        *ptr = '\0';
        ptr ++;
+       ippfind_output = (char *)malloc(MAX_OUTPUT_LEN*(sizeof(char)));
        snprintf(ippfind_output, MAX_OUTPUT_LEN, "%s", ptr);
        cupsArrayAdd(service_uri_list_ipps, ippfind_output);
       } else if ((!strncasecmp(ptr, "ipp", 3) && ptr[3] == '\t')) {
        ptr += 3;
        *ptr = '\0';
        ptr ++;
+       ippfind_output = (char *)malloc(MAX_OUTPUT_LEN*(sizeof(char)));
        snprintf(ippfind_output, MAX_OUTPUT_LEN, "%s", ptr);
        cupsArrayAdd(service_uri_list_ipp, ippfind_output);
       } else