]> arthur.barton.de Git - netatalk.git/blobdiff - etc/papd/printcap.c
- merge branch-netatalk-afp-3x-dev, HEAD was tagged before
[netatalk.git] / etc / papd / printcap.c
index 633ff4ebf6a1067a70f5602255458cf2c868bcc0..19ed788331cc8351de1a76774a9fe532b0930f33 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: printcap.c,v 1.5 2001-07-31 19:50:14 srittau Exp $
+ * $Id: printcap.c,v 1.10 2005-04-28 20:49:49 bfernhomberg Exp $
  *
  * Copyright (c) 1990,1994 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-#ifndef lint
-static char sccsid[] = "@(#)printcap.c 5.7 (Berkeley) 3/4/91";
-#endif /* not lint */
-
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
@@ -108,18 +104,24 @@ char      *getenv();
  * Added a "cap" parameter, so we can use these calls for printcap
  * and papd.conf.
  */
-int getprent( cap, bp)
+int getprent( cap, bp, bufsize )
        register char *cap;
        register char *bp;
+       register int bufsize;
 {
-       register int c, skip = 0;
+       register int c, skip = 0, i;
 
        if (pfp == NULL && (pfp = fopen( cap, "r")) == NULL)
                return(-1);
        tbuf = bp;
+       i = 0;
        for (;;) {
                switch (c = getc(pfp)) {
                case EOF:
+                        if (bp != tbuf) {
+                               *bp = '\0';
+                               return(1);
+                       }
                        fclose(pfp);
                        pfp = NULL;
                        return(0);
@@ -146,6 +148,13 @@ int getprent( cap, bp)
                                return(1);
                        }
                        *bp++ = c;
+                       if (++i >= bufsize) {
+                               write(2, "config file too large\n", 22);
+                               fclose(pfp);
+                               pfp = NULL;
+                               *bp = '\0';
+                               return(1);
+                       }
                }
        }
 }
@@ -172,6 +181,7 @@ int tgetent( cap, bp, name)
        register int i = 0, cnt = 0;
        char ibuf[BUFSIZ];
        int tf;
+       int skip;
 
        hopcount = 0;
        tbuf = bp;
@@ -190,7 +200,7 @@ int tgetent( cap, bp, name)
                        cp2 = getenv("TERM");
                        if (cp2==(char *) 0 || strcmp(name,cp2)==0) {
                                strcpy(bp,cp);
-                               return(tnchktc());
+                               return(tnchktc(cap));
                        } else {
                                tf = open(cap, 0);
                        }
@@ -199,13 +209,14 @@ int tgetent( cap, bp, name)
        }
        if (tf==0)
                tf = open(cap, 0);
-#else
+#else /* V6 */
        tf = open(cap, 0);
-#endif
+#endif /* V6 */
        if (tf < 0)
                return (-1);
        for (;;) {
                cp = bp;
+               skip = 0;
                for (;;) {
                        if (i == cnt) {
                                cnt = read(tf, ibuf, BUFSIZ);
@@ -217,12 +228,20 @@ int tgetent( cap, bp, name)
                        }
                        c = ibuf[i++];
                        if (c == '\n') {
-                               if (cp > bp && cp[-1] == '\\'){
+                               if (!skip && cp > bp && cp[-1] == '\\') {
                                        cp--;
                                        continue;
                                }
-                               break;
+                               skip = 0;
+                               if (cp == bp)
+                                       continue;
+                               else
+                                       break;
                        }
+                       if (c == '#' && cp == bp)
+                               skip++;
+                       if (skip)
+                               continue;
                        if (cp >= bp+BUFSIZ) {
                                write(2,"Termcap entry too long\n", 23);
                                break;
@@ -332,7 +351,7 @@ tskip(bp)
 
        while (*bp && *bp != ':')
                bp++;
-       if (*bp == ':')
+       while (*bp && *bp == ':')
                bp++;
        return (bp);
 }
@@ -475,9 +494,10 @@ nextc:
 }
 
 static char *
-decodename(str, area)
+decodename(str, area, bufsize)
        register char *str;
        char **area;
+       int bufsize;
 {
        register char *cp;
        register int c;
@@ -485,7 +505,7 @@ decodename(str, area)
        int i;
 
        cp = *area;
-       while ((c = *str++) && c != ':' && c != '|' ) {
+       while ((c = *str++) && --bufsize && c != ':' && c != '|' ) {
                switch (c) {
 
                case '^':
@@ -520,8 +540,9 @@ nextc:
 }
 
 char *
-getpname( area )
-    char       **area;
+getpname( area, bufsize )
+       char    **area;
+       int     bufsize;
 {
-    return( decodename( tbuf, area ));
+       return( decodename( tbuf, area, bufsize));
 }