Bug 11147

Summary: parse_printcap broken
Product: [Retired] Red Hat Linux Reporter: Andrew Schretter <schrett>
Component: xfigAssignee: Than Ngo <than>
Status: CLOSED RAWHIDE QA Contact:
Severity: high Docs Contact:
Priority: medium    
Version: 6.2   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2000-06-26 19:45:35 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Andrew Schretter 2000-05-01 15:59:59 UTC
I have already submitted this patch to the xfig maintainer in hopes
that he'll incorporate it there.  The problem is that the parse_printcap
function in w_print.c does not take into account duplicate print entries
(minor problem) and does not discard blank printer names (major problem).
The latter is killer since it takes any blank space at the beginning
of a line as a printer name and there is a hardcoded limit of 200 printers
in the the code.  Even with our 25 printers, appearing twice in the
printcap each, there were 215 that came up and crashed xfig anytime you
tried to print.

Here is the patch to fix it.
--- xfig.3.2.3-beta-1/w_print.c Wed Sep 22 14:56:58 1999
+++ xfig.3.2.3-beta-1.new/w_print.c     Mon May  1 11:36:56 2000
@@ -967,9 +967,10 @@
 {
     FILE   *printcap;
     char    str[300];
-    int     i,j,len;
+    int     i,j,k,len;
     int     printers;
     Boolean comment;
+    Boolean dudprinter;
     if ((printcap=fopen("/etc/printcap","r"))==NULL)
        return 0;
@@ -1002,6 +1003,20 @@
                break;
        }
        str[j] = '\0';
+        /* Check for empty printer name or duplicate name */
+        dudprinter = True;
+        for (k=0; k<j; k++) {
+            if(str[k] !=' ' && str[k] != '\t')
+               dudprinter = False;
+        }
+        if(printers > 0) {
+            for (k=0; k<printers; k++) {
+                if(strncmp(names[k],&str[i],j-i+1) == 0)
+                    dudprinter = True;
+            }
+        }
+        if (dudprinter == True)
+            continue;
        if ((names[printers] = malloc(j-i+1)) == NULL)
            return printers;
        strncpy(names[printers],&str[i],j-i+1);

Andrew

Comment 1 Than Ngo 2000-08-05 13:07:28 UTC
added the patch in xfig-3.2.3c for RC1.