diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2007-09-11 15:47:18 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2007-09-11 15:47:18 +0000 |
commit | a8ba60ecf20c221bd24ff666339eb5edcbbbac33 (patch) | |
tree | 650532cc79cb8294b5e7739a5b61676601594950 /usr.bin/sup | |
parent | d0c98e555e46b02b8df61047ae1c820859b23e93 (diff) |
use strcspn to properly overwrite '\n' in fgets returned buffer
ok pyr@, ray@, millert@, moritz@, chl@
Diffstat (limited to 'usr.bin/sup')
-rw-r--r-- | usr.bin/sup/src/scan.c | 22 | ||||
-rw-r--r-- | usr.bin/sup/src/supcmain.c | 5 | ||||
-rw-r--r-- | usr.bin/sup/src/supcmeat.c | 8 | ||||
-rw-r--r-- | usr.bin/sup/src/supcname.c | 5 | ||||
-rw-r--r-- | usr.bin/sup/src/supfilesrv.c | 27 | ||||
-rw-r--r-- | usr.bin/sup/src/supscan.c | 18 |
6 files changed, 30 insertions, 55 deletions
diff --git a/usr.bin/sup/src/scan.c b/usr.bin/sup/src/scan.c index 377dbd1b954..5b4d5996ed3 100644 --- a/usr.bin/sup/src/scan.c +++ b/usr.bin/sup/src/scan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scan.c,v 1.15 2003/07/10 00:06:51 david Exp $ */ +/* $OpenBSD: scan.c,v 1.16 2007/09/11 15:47:17 gilles Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -302,9 +302,7 @@ getrelease (release) rewound = TRUE; continue; } - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; q = nxtarg(&p, " \t"); @@ -350,9 +348,7 @@ makescanlists() f = fopen(buf, "r"); if (f != NULL) { while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p,'\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; q = nxtarg(&p, " \t"); @@ -479,8 +475,7 @@ readlistfile(fname) goaway("Can't read list file %s", fname); cdprefix(prefix); while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - if ((q = strchr(p, '\n')) != NULL) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; q = nxtarg (&p, " \t"); @@ -869,8 +864,9 @@ int getscanfile(scanfile) (void) fclose(f); return (FALSE); } - if ((q = strchr(p,'\n')) != NULL) - *q = '\0'; + + p[strcspn(p, "\n")] = '\0'; + if (*p++ != 'V') { (void) fclose(f); return (FALSE); @@ -887,9 +883,7 @@ int getscanfile(scanfile) } notwanted = FALSE; while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; ts.Tflags = 0; if (*p == 'X') { if (notwanted) diff --git a/usr.bin/sup/src/supcmain.c b/usr.bin/sup/src/supcmain.c index f25e0618f5e..d745152d2a1 100644 --- a/usr.bin/sup/src/supcmain.c +++ b/usr.bin/sup/src/supcmain.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supcmain.c,v 1.20 2005/04/27 18:13:16 mickey Exp $ */ +/* $OpenBSD: supcmain.c,v 1.21 2007/09/11 15:47:17 gilles Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -666,8 +666,7 @@ init(argc, argv) lastC = NULL; bogus = FALSE; while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - if ((q = strchr(p, '\n'))) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; arg = nxtarg (&p, " \t"); diff --git a/usr.bin/sup/src/supcmeat.c b/usr.bin/sup/src/supcmeat.c index ee5b191d72b..d0585ae5625 100644 --- a/usr.bin/sup/src/supcmeat.c +++ b/usr.bin/sup/src/supcmeat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supcmeat.c,v 1.21 2005/04/27 18:13:16 mickey Exp $ */ +/* $OpenBSD: supcmeat.c,v 1.22 2007/09/11 15:47:17 gilles Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -501,8 +501,7 @@ listfiles() f = fopen(buf, "r"); if (f) { while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - if ((q = strchr(p, '\n'))) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; (void) Tinsert(&lastT, p, FALSE); @@ -514,8 +513,7 @@ listfiles() f = fopen(buf, "r"); if (f) { while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - if ((q = strchr(p, '\n'))) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; (void) Tinsert(&refuseT, p, FALSE); diff --git a/usr.bin/sup/src/supcname.c b/usr.bin/sup/src/supcname.c index a4020b61dc4..fd468bd2974 100644 --- a/usr.bin/sup/src/supcname.c +++ b/usr.bin/sup/src/supcname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supcname.c,v 1.7 2001/05/04 22:16:16 millert Exp $ */ +/* $OpenBSD: supcname.c,v 1.8 2007/09/11 15:47:17 gilles Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -83,8 +83,7 @@ getnams() if (f == NULL) logquit (1, "Can't open %s", buf); while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - if ((q = strchr(p, '\n')) != NULL) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; q = nxtarg(&p, "= \t"); diff --git a/usr.bin/sup/src/supfilesrv.c b/usr.bin/sup/src/supfilesrv.c index 458f0fc5a38..3a6517691b1 100644 --- a/usr.bin/sup/src/supfilesrv.c +++ b/usr.bin/sup/src/supfilesrv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supfilesrv.c,v 1.36 2006/03/04 16:18:06 miod Exp $ */ +/* $OpenBSD: supfilesrv.c,v 1.37 2007/09/11 15:47:17 gilles Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -637,11 +637,13 @@ init(argc, argv) if (f == NULL) quit(1, "Unable to open cryptfile %s\n", cryptkey); if ((p = fgets(buf, sizeof(buf), f)) != NULL) { - if ((q = strchr(p, '\n'))) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (*p == '\0') quit(1, "No cryptkey found in %s\n", cryptkey); cryptkey = strdup(buf); + if (cryptkey == NULL) + quit(1, "Unable to allocate memory\n"); + } (void) fclose(f); x = request (dbgportsq ? DEBUGFPORT : FILEPORT, clienthost, &maxsleep); @@ -864,9 +866,7 @@ srvsetup() struct stat fsbuf; while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; q = nxtarg(&p, " \t"); @@ -922,9 +922,7 @@ srvsetup() f = fopen(buf, "r"); if (f) { while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; q = nxtarg(&p, " \t="); @@ -948,9 +946,7 @@ srvsetup() f = fopen(buf, "r"); if (f) { while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; prefix = strdup(p); @@ -1002,9 +998,7 @@ srvsetup() while ((p = fgets (buf, sizeof(buf), f)) != NULL) { int not; - q = strchr (p,'\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; q = nxtarg(&p, " \t"); @@ -1080,8 +1074,7 @@ docrypt() if (cryptkey == NULL && (p = fgets(buf, sizeof(buf), f))) { - if ((q = strchr(p, '\n')) != NULL) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (*p) cryptkey = strdup(buf); } diff --git a/usr.bin/sup/src/supscan.c b/usr.bin/sup/src/supscan.c index cfde90008e8..3ab619fa60a 100644 --- a/usr.bin/sup/src/supscan.c +++ b/usr.bin/sup/src/supscan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supscan.c,v 1.14 2006/01/23 17:29:22 millert Exp $ */ +/* $OpenBSD: supscan.c,v 1.15 2007/09/11 15:47:17 gilles Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -276,9 +276,7 @@ init(argc, argv) if ((f = fopen(buf, "r")) == NULL) quit(1, "supscan: Unable to open %s\n", buf); while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; collname = nxtarg(&p, " \t="); @@ -298,9 +296,7 @@ init(argc, argv) if ((f = fopen(filename, "r")) == NULL) quit(1, "supscan: Unable to open %s\n", filename); while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:",*p)) continue; q = nxtarg(&p, " \t="); @@ -329,9 +325,7 @@ getscancoll(filename, collname, basedir) if (basedir == NULL) { if ((f = fopen(filename, "r")) != NULL) { while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; q = nxtarg(&p, " \t="); @@ -359,9 +353,7 @@ getscancoll(filename, collname, basedir) (void) snprintf(buf, sizeof buf, FILEPREFIX, collname); if ((f = fopen(buf, "r")) != NULL) { while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - q = strchr(p, '\n'); - if (q) - *q = '\0'; + p[strcspn(p, "\n")] = '\0'; if (strchr("#;:", *p)) continue; prefix = strdup(p); |