summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:47:18 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:47:18 +0000
commita8ba60ecf20c221bd24ff666339eb5edcbbbac33 (patch)
tree650532cc79cb8294b5e7739a5b61676601594950
parentd0c98e555e46b02b8df61047ae1c820859b23e93 (diff)
use strcspn to properly overwrite '\n' in fgets returned buffer
ok pyr@, ray@, millert@, moritz@, chl@
-rw-r--r--usr.bin/diff/diffreg.c10
-rw-r--r--usr.bin/file/print.c7
-rw-r--r--usr.bin/file/softmagic.c11
-rw-r--r--usr.bin/ftp/cmds.c11
-rw-r--r--usr.bin/ftp/util.c14
-rw-r--r--usr.bin/gzsig/sign.c5
-rw-r--r--usr.bin/mg/dired.c7
-rw-r--r--usr.bin/rcs/diff.c9
-rw-r--r--usr.bin/rdist/message.c7
-rw-r--r--usr.bin/ssh/session.c7
-rw-r--r--usr.bin/ssh/ssh-keygen.c8
-rw-r--r--usr.bin/ssh/sshlogin.c5
-rw-r--r--usr.bin/sup/src/scan.c22
-rw-r--r--usr.bin/sup/src/supcmain.c5
-rw-r--r--usr.bin/sup/src/supcmeat.c8
-rw-r--r--usr.bin/sup/src/supcname.c5
-rw-r--r--usr.bin/sup/src/supfilesrv.c27
-rw-r--r--usr.bin/sup/src/supscan.c18
-rw-r--r--usr.bin/systat/disks.c9
-rw-r--r--usr.bin/systat/netcmds.c9
-rw-r--r--usr.bin/tset/tset.c5
-rw-r--r--usr.bin/vacation/vacation.c13
-rw-r--r--usr.bin/vi/common/recover.c5
-rw-r--r--usr.bin/vi/ex/ex_cscope.c5
24 files changed, 91 insertions, 141 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 4bb8d9e1d74..53209117025 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.69 2007/06/09 05:16:21 ray Exp $ */
+/* $OpenBSD: diffreg.c,v 1.70 2007/09/11 15:47:17 gilles Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -65,7 +65,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.69 2007/06/09 05:16:21 ray Exp $";
+static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.70 2007/09/11 15:47:17 gilles Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -1300,7 +1300,6 @@ match_function(const long *f, int pos, FILE *file)
unsigned char buf[FUNCTION_CONTEXT_SIZE];
size_t nc;
int last = lastline;
- char *p;
char *state = NULL;
lastline = pos;
@@ -1312,9 +1311,8 @@ match_function(const long *f, int pos, FILE *file)
nc = fread(buf, 1, nc, file);
if (nc > 0) {
buf[nc] = '\0';
- p = strchr(buf, '\n');
- if (p != NULL)
- *p = '\0';
+ buf[strcspn(buf, "\n")] = '\0';
+
if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
if (begins_with(buf, "private:")) {
if (!state)
diff --git a/usr.bin/file/print.c b/usr.bin/file/print.c
index 9b172d37a06..1271370d843 100644
--- a/usr.bin/file/print.c
+++ b/usr.bin/file/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.11 2004/05/19 02:32:35 tedu Exp $ */
+/* $OpenBSD: print.c,v 1.12 2007/09/11 15:47:17 gilles Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -42,7 +42,7 @@
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.11 2004/05/19 02:32:35 tedu Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.12 2007/09/11 15:47:17 gilles Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@@ -181,7 +181,6 @@ file_fmttime(uint32_t v, int local)
pp = asctime(tm);
}
- if ((rt = strchr(pp, '\n')) != NULL)
- *rt = '\0';
+ pp[strcspn(pp, "\n")] = '\0';
return pp;
}
diff --git a/usr.bin/file/softmagic.c b/usr.bin/file/softmagic.c
index fda453a1ec9..4c9ecc9a09b 100644
--- a/usr.bin/file/softmagic.c
+++ b/usr.bin/file/softmagic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softmagic.c,v 1.11 2004/05/19 02:32:36 tedu Exp $ */
+/* $OpenBSD: softmagic.c,v 1.12 2007/09/11 15:47:17 gilles Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -40,7 +40,7 @@
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.11 2004/05/19 02:32:36 tedu Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.12 2007/09/11 15:47:17 gilles Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
@@ -278,11 +278,8 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
t = m->offset + strlen(m->value.s);
}
else {
- if (*m->value.s == '\0') {
- char *cp = strchr(p->s,'\n');
- if (cp)
- *cp = '\0';
- }
+ if (*m->value.s == '\0')
+ p->s[strcspn(p->s, "\n")] = '\0';
if (file_printf(ms, m->desc, p->s) == -1)
return -1;
t = m->offset + strlen(p->s);
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c
index e0b73fab19c..2f43bb6894a 100644
--- a/usr.bin/ftp/cmds.c
+++ b/usr.bin/ftp/cmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmds.c,v 1.56 2007/07/26 17:48:41 millert Exp $ */
+/* $OpenBSD: cmds.c,v 1.57 2007/09/11 15:47:17 gilles Exp $ */
/* $NetBSD: cmds.c,v 1.27 1997/08/18 10:20:15 lukem Exp $ */
/*
@@ -60,7 +60,7 @@
*/
#if !defined(lint) && !defined(SMALL)
-static const char rcsid[] = "$OpenBSD: cmds.c,v 1.56 2007/07/26 17:48:41 millert Exp $";
+static const char rcsid[] = "$OpenBSD: cmds.c,v 1.57 2007/09/11 15:47:17 gilles Exp $";
#endif /* not lint and not SMALL */
/*
@@ -1272,14 +1272,13 @@ user(int argc, char *argv[])
}
if (n == CONTINUE) {
if (argc < 4) {
- char *p;
-
(void)fputs("Account: ", ttyout);
(void)fflush(ttyout);
if (fgets(acctname, sizeof(acctname), stdin) == NULL)
goto fail;
- if ((p = strchr(acctname, '\n')) != NULL)
- *p = '\0';
+
+ acctname[strcspn(acctname, "\n")] = '\0';
+
argv[3] = acctname;
argc++;
}
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index c03a9034003..7ebe58a15de 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.46 2007/06/06 19:15:33 pyr Exp $ */
+/* $OpenBSD: util.c,v 1.47 2007/09/11 15:47:17 gilles Exp $ */
/* $NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $ */
/*-
@@ -71,7 +71,7 @@
*/
#if !defined(lint) && !defined(SMALL)
-static const char rcsid[] = "$OpenBSD: util.c,v 1.46 2007/06/06 19:15:33 pyr Exp $";
+static const char rcsid[] = "$OpenBSD: util.c,v 1.47 2007/09/11 15:47:17 gilles Exp $";
#endif /* not lint and not SMALL */
/*
@@ -312,10 +312,7 @@ tryagain:
fprintf(ttyout, "Name (%s): ", host);
user = myname;
if (fgets(tmp, sizeof(tmp), stdin) != NULL) {
- char *p;
-
- if ((p = strchr(tmp, '\n')) != NULL)
- *p = '\0';
+ tmp[strcspn(tmp, "\n")] = '\0';
if (tmp[0] != '\0')
user = tmp;
}
@@ -469,8 +466,9 @@ remglob(char *argv[], int doswitch, char **errbuf)
ftemp = NULL;
return (NULL);
}
- if ((cp = strchr(buf, '\n')) != NULL)
- *cp = '\0';
+
+ buf[strcspn(buf, "\n")] = '\0';
+
return (buf);
}
diff --git a/usr.bin/gzsig/sign.c b/usr.bin/gzsig/sign.c
index dc073fc7afb..795add21f0f 100644
--- a/usr.bin/gzsig/sign.c
+++ b/usr.bin/gzsig/sign.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sign.c,v 1.7 2006/04/17 09:36:56 moritz Exp $ */
+/* $OpenBSD: sign.c,v 1.8 2007/09/11 15:47:17 gilles Exp $ */
/*
* sign.c
@@ -200,8 +200,7 @@ sign_passwd_cb(char *buf, int size, int rwflag, void *u)
if (fgets(buf, size, f) == NULL)
err(1, "fgets(%.64s)", passphrase_file);
fclose(f);
- if ((p = strchr(buf, '\n')) != NULL)
- *p = '\0';
+ buf[strcspn(buf, "\n")] = '\0';
} else {
p = getpass("Enter passphrase: ");
if (strlcpy(buf, p, size) >= size)
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
index ba44d6c0e8d..27c37b4bb4b 100644
--- a/usr.bin/mg/dired.c
+++ b/usr.bin/mg/dired.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dired.c,v 1.42 2006/11/01 06:02:29 ray Exp $ */
+/* $OpenBSD: dired.c,v 1.43 2007/09/11 15:47:17 gilles Exp $ */
/* This file is in the public domain. */
@@ -622,10 +622,7 @@ dired_(char *dname)
}
line[0] = line[1] = ' ';
while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {
- char *p;
-
- if ((p = strchr(line, '\n')) != NULL)
- *p = '\0'; /* remove ^J */
+ line[strcspn(line, "\n")] = '\0'; /* remove ^J */
(void) addline(bp, line);
}
if (pclose(dirpipe) == -1) {
diff --git a/usr.bin/rcs/diff.c b/usr.bin/rcs/diff.c
index 69f8f0f6e57..1a85f589a1b 100644
--- a/usr.bin/rcs/diff.c
+++ b/usr.bin/rcs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.24 2007/07/03 00:56:23 ray Exp $ */
+/* $OpenBSD: diff.c,v 1.25 2007/09/11 15:47:17 gilles Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -1155,7 +1155,6 @@ match_function(const long *f, int pos, FILE *fp)
unsigned char buf[FUNCTION_CONTEXT_SIZE];
size_t nc;
int last = lastline;
- char *p;
char *state = NULL;
lastline = pos;
@@ -1167,9 +1166,9 @@ match_function(const long *f, int pos, FILE *fp)
nc = fread(buf, 1, nc, fp);
if (nc > 0) {
buf[nc] = '\0';
- p = strchr((const char *)buf, '\n');
- if (p != NULL)
- *p = '\0';
+
+ buf[strcspn(buf, "\n")] = '\0';
+
if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
if (begins_with(buf, "private:")) {
if (!state)
diff --git a/usr.bin/rdist/message.c b/usr.bin/rdist/message.c
index ce3d7dbe420..54bf099f0df 100644
--- a/usr.bin/rdist/message.c
+++ b/usr.bin/rdist/message.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: message.c,v 1.15 2003/06/03 02:56:14 millert Exp $ */
+/* $OpenBSD: message.c,v 1.16 2007/09/11 15:47:17 gilles Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -37,7 +37,7 @@ static char RCSid[] __attribute__((__unused__)) =
"$From: message.c,v 1.5 1999/11/01 00:21:39 christos Exp $";
#else
static char RCSid[] __attribute__((__unused__)) =
-"$OpenBSD: message.c,v 1.15 2003/06/03 02:56:14 millert Exp $";
+"$OpenBSD: message.c,v 1.16 2007/09/11 15:47:17 gilles Exp $";
#endif
static char sccsid[] __attribute__((__unused__)) =
@@ -517,8 +517,7 @@ _message(int flags, char *msgbuf)
/*
* Ensure no stray newlines are present
*/
- if ((cp = strchr(msgbuf, '\n')) != NULL)
- *cp = CNULL;
+ msgbuf[strcspn(msgbuf, "\n")] = CNULL;
checkhostname();
if (strncmp(currenthost, msgbuf, strlen(currenthost)) == 0)
diff --git a/usr.bin/ssh/session.c b/usr.bin/ssh/session.c
index 435dfeecfe9..f9fc444fdd2 100644
--- a/usr.bin/ssh/session.c
+++ b/usr.bin/ssh/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.223 2007/08/23 02:55:51 djm Exp $ */
+/* $OpenBSD: session.c,v 1.224 2007/09/11 15:47:17 gilles Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@@ -724,8 +724,9 @@ read_environment_file(char ***env, u_int *envsize,
;
if (!*cp || *cp == '#' || *cp == '\n')
continue;
- if (strchr(cp, '\n'))
- *strchr(cp, '\n') = '\0';
+
+ cp[strcspn(cp, "\n")] = '\0';
+
value = strchr(cp, '=');
if (value == NULL) {
fprintf(stderr, "Bad line %u in %.100s\n", lineno,
diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c
index adcd937a6d1..fb4261ae6c0 100644
--- a/usr.bin/ssh/ssh-keygen.c
+++ b/usr.bin/ssh/ssh-keygen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keygen.c,v 1.161 2007/09/09 11:38:01 sobrado Exp $ */
+/* $OpenBSD: ssh-keygen.c,v 1.162 2007/09/11 15:47:17 gilles Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -134,8 +134,7 @@ ask_filename(struct passwd *pw, const char *prompt)
fprintf(stderr, "%s (%s): ", prompt, identity_file);
if (fgets(buf, sizeof(buf), stdin) == NULL)
exit(1);
- if (strchr(buf, '\n'))
- *strchr(buf, '\n') = 0;
+ buf[strcspn(buf, "\n")] = '\0';
if (strcmp(buf, "") != 0)
strlcpy(identity_file, buf, sizeof(identity_file));
have_identity = 1;
@@ -955,8 +954,7 @@ do_change_comment(struct passwd *pw)
key_free(private);
exit(1);
}
- if (strchr(new_comment, '\n'))
- *strchr(new_comment, '\n') = 0;
+ new_comment[strcspn(new_comment, "\n")] = '\0';
}
/* Save the file using the new passphrase. */
diff --git a/usr.bin/ssh/sshlogin.c b/usr.bin/ssh/sshlogin.c
index 44bf5c65331..361562b69e9 100644
--- a/usr.bin/ssh/sshlogin.c
+++ b/usr.bin/ssh/sshlogin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshlogin.c,v 1.25 2006/08/03 03:34:42 deraadt Exp $ */
+/* $OpenBSD: sshlogin.c,v 1.26 2007/09/11 15:47:17 gilles Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -122,8 +122,7 @@ store_lastlog_message(const char *user, uid_t uid)
if (last_login_time != 0) {
time_string = ctime(&last_login_time);
- if (strchr(time_string, '\n'))
- *strchr(time_string, '\n') = '\0';
+ time_string[strcspn(time_string, "\n")] = '\0';
if (strcmp(hostname, "") == 0)
snprintf(buf, sizeof(buf), "Last login: %s\r\n",
time_string);
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);
diff --git a/usr.bin/systat/disks.c b/usr.bin/systat/disks.c
index 909bb6b85e3..c08bbbef200 100644
--- a/usr.bin/systat/disks.c
+++ b/usr.bin/systat/disks.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disks.c,v 1.16 2007/03/20 03:56:13 tedu Exp $ */
+/* $OpenBSD: disks.c,v 1.17 2007/09/11 15:47:17 gilles Exp $ */
/* $NetBSD: disks.c,v 1.4 1996/05/10 23:16:33 thorpej Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)disks.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: disks.c,v 1.16 2007/03/20 03:56:13 tedu Exp $";
+static char rcsid[] = "$OpenBSD: disks.c,v 1.17 2007/09/11 15:47:17 gilles Exp $";
#endif /* not lint */
#include <string.h>
@@ -74,9 +74,8 @@ dkselect(char *args, int truefalse, int selections[])
char *cp;
int i;
- cp = strchr(args, '\n');
- if (cp)
- *cp = '\0';
+ args[strcspn(args, "\n")] = '\0';
+
for (;;) {
for (cp = args; isspace(*cp); cp++)
;
diff --git a/usr.bin/systat/netcmds.c b/usr.bin/systat/netcmds.c
index 1c1c6bb0765..527b33f87e3 100644
--- a/usr.bin/systat/netcmds.c
+++ b/usr.bin/systat/netcmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcmds.c,v 1.18 2007/08/09 02:38:09 ray Exp $ */
+/* $OpenBSD: netcmds.c,v 1.19 2007/09/11 15:47:17 gilles Exp $ */
/* $NetBSD: netcmds.c,v 1.4 1995/05/21 17:14:38 mycroft Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)netcmds.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: netcmds.c,v 1.18 2007/08/09 02:38:09 ray Exp $";
+static char rcsid[] = "$OpenBSD: netcmds.c,v 1.19 2007/09/11 15:47:17 gilles Exp $";
#endif /* not lint */
/*
@@ -129,9 +129,8 @@ changeitems(char *args, int onoff)
struct servent *sp;
struct addrinfo hints, *res0, *res;
- cp = strchr(args, '\n');
- if (cp)
- *cp = '\0';
+ args[strcspn(args, "\n")] = '\0';
+
for (;;args = cp) {
for (cp = args; isspace(*cp); cp++)
;
diff --git a/usr.bin/tset/tset.c b/usr.bin/tset/tset.c
index f44bafa1882..8495bff787d 100644
--- a/usr.bin/tset/tset.c
+++ b/usr.bin/tset/tset.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tset.c,v 1.29 2007/02/20 01:52:01 ray Exp $ */
+/* $OpenBSD: tset.c,v 1.30 2007/09/11 15:47:17 gilles Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
@@ -204,8 +204,7 @@ askuser(const char *dflt)
return (dflt);
}
- if ((p = strchr(answer, '\n')) != 0)
- *p = '\0';
+ answer[strcspn(answer, "\n")] = '\0';
if (answer[0])
return (answer);
if (dflt != 0)
diff --git a/usr.bin/vacation/vacation.c b/usr.bin/vacation/vacation.c
index eab4c0925dc..a9d1f639cb9 100644
--- a/usr.bin/vacation/vacation.c
+++ b/usr.bin/vacation/vacation.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vacation.c,v 1.29 2007/03/21 03:31:19 tedu Exp $ */
+/* $OpenBSD: vacation.c,v 1.30 2007/09/11 15:47:17 gilles Exp $ */
/* $NetBSD: vacation.c,v 1.7 1995/04/29 05:58:27 cgd Exp $ */
/*
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)vacation.c 8.2 (Berkeley) 1/26/94";
#endif
-static char rcsid[] = "$OpenBSD: vacation.c,v 1.29 2007/03/21 03:31:19 tedu Exp $";
+static char rcsid[] = "$OpenBSD: vacation.c,v 1.30 2007/09/11 15:47:17 gilles Exp $";
#endif /* not lint */
/*
@@ -235,8 +235,7 @@ readheaders(void)
;
*p = '\0';
(void)strlcpy(from, buf + 5, sizeof(from));
- if ((p = strchr(from, '\n')))
- *p = '\0';
+ from[strcspn(from, "\n")] = '\0';
if (junkmail())
exit(0);
}
@@ -265,8 +264,7 @@ readheaders(void)
"Return-Path %s exceeds limits", p);
exit(1);
}
- if ((p = strchr(from, '\n')))
- *p = '\0';
+ from[strcspn(from, "\n")] = '\0';
if (junkmail())
exit(0);
break;
@@ -296,8 +294,7 @@ readheaders(void)
"Subject %s exceeds limits", p);
exit(1);
}
- if ((p = strchr(subj, '\n')))
- *p = '\0';
+ subj[strcspn(subj, "\n")] = '\0';
break;
case 'C': /* "Cc:" */
case 'c':
diff --git a/usr.bin/vi/common/recover.c b/usr.bin/vi/common/recover.c
index c47f7809464..6d4655d486c 100644
--- a/usr.bin/vi/common/recover.c
+++ b/usr.bin/vi/common/recover.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: recover.c,v 1.11 2006/12/11 20:50:55 deraadt Exp $ */
+/* $OpenBSD: recover.c,v 1.12 2007/09/11 15:47:17 gilles Exp $ */
/*-
* Copyright (c) 1993, 1994
@@ -817,8 +817,7 @@ rcv_gets(buf, len, fd)
if ((nr = read(fd, buf, len - 1)) == -1)
return (NULL);
buf[nr] = '\0';
- if ((p = strchr(buf, '\n')) == NULL)
- return (NULL);
+ buf[strcspn(buf, "\n")] = '\0';
(void)lseek(fd, (off_t)((p - buf) + 1), SEEK_SET);
return (buf);
}
diff --git a/usr.bin/vi/ex/ex_cscope.c b/usr.bin/vi/ex/ex_cscope.c
index 7bd12194599..dc7a66de5b2 100644
--- a/usr.bin/vi/ex/ex_cscope.c
+++ b/usr.bin/vi/ex/ex_cscope.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex_cscope.c,v 1.13 2007/03/20 03:56:13 tedu Exp $ */
+/* $OpenBSD: ex_cscope.c,v 1.14 2007/09/11 15:47:17 gilles Exp $ */
/*-
* Copyright (c) 1994, 1996
@@ -675,8 +675,7 @@ parse(sp, csc, tqp, matchesp)
#define CSCOPE_NLINES_FMT "cscope: %d lines%1[\n]"
if (sscanf(buf, CSCOPE_NLINES_FMT, &nlines, dummy) == 2)
break;
- if ((p = strchr(buf, '\n')) != NULL)
- *p = '\0';
+ buf[strcspn(buf, "\n")] = '\0';
msgq(sp, M_ERR, "%s: \"%s\"", csc->dname, buf);
}