summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:25:15 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:25:15 +0000
commitd0c98e555e46b02b8df61047ae1c820859b23e93 (patch)
treedba21468402ae46d796b5c30da4a859ae107a29f /sbin
parent18590f6c720ae49a5bb4d811e6827d85c513fcfe (diff)
use strcspn to properly overwrite '\n' in fgets returned buffer
ok pyr@, ray@, millert@, moritz@, chl@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/raidctl/rf_configure.c16
-rw-r--r--sbin/savecore/savecore.c13
2 files changed, 10 insertions, 19 deletions
diff --git a/sbin/raidctl/rf_configure.c b/sbin/raidctl/rf_configure.c
index a3423674728..63d91b36add 100644
--- a/sbin/raidctl/rf_configure.c
+++ b/sbin/raidctl/rf_configure.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rf_configure.c,v 1.16 2007/02/18 20:16:04 ray Exp $ */
+/* $OpenBSD: rf_configure.c,v 1.17 2007/09/11 15:25:14 gilles Exp $ */
/* $NetBSD: rf_configure.c,v 1.14 2001/02/04 21:05:42 christos Exp $ */
/*
@@ -333,10 +333,8 @@ rf_MakeLayoutSpecificDeclustered(FILE *configfp, RF_Config_t *cfgPtr, void *arg)
"Can't find block design file name in config file\n"))
return(EINVAL);
bdfile = rf_find_non_white(buf);
- if ((p = strchr(bdfile, '\n')) != NULL) {
- /* strip newline char */
- *p = '\0';
- }
+ bdfile[strcspn(bdfile, "\n")] = '\0';
+
/* open bd file, check validity of configuration */
if ((fp = fopen(bdfile,"r"))==NULL) {
RF_ERRORMSG1("RAID: config error: Can't open layout table file %s\n",bdfile);
@@ -360,10 +358,7 @@ rf_MakeLayoutSpecificDeclustered(FILE *configfp, RF_Config_t *cfgPtr, void *arg)
"Can't find sparemap file name in config file\n"))
return(EINVAL);
smname = rf_find_non_white(smbuf);
- if ((p = strchr(smname, '\n')) != NULL) {
- /* strip newline char */
- *p = '\0';
- }
+ smname[strcspn(smname, "\n")] = '\0';
} else {
smbuf[0] = '\0';
smname = smbuf;
@@ -520,8 +515,7 @@ rf_ReadSpareTable(RF_SparetWait_t *req, char *fname)
if (rf_get_next_nonblank_line(buf, 1024, fp,
"Invalid sparemap file: can't find header line\n"))
return(NULL);
- if ((p = strchr(buf, '\n')) != NULL)
- *p = '\0';
+ buf[strcspn(buf, "\n")] = '\0';
snprintf(targString, sizeof targString, "fdisk %d\n", req->fcol);
snprintf(errString, sizeof errString,
diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c
index d1bf1766ae8..e89889d8235 100644
--- a/sbin/savecore/savecore.c
+++ b/sbin/savecore/savecore.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: savecore.c,v 1.42 2005/01/07 21:57:10 millert Exp $ */
+/* $OpenBSD: savecore.c,v 1.43 2007/09/11 15:25:14 gilles Exp $ */
/* $NetBSD: savecore.c,v 1.26 1996/03/18 21:16:05 leo Exp $ */
/*-
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) 1/2/94";
#else
-static char rcsid[] = "$OpenBSD: savecore.c,v 1.42 2005/01/07 21:57:10 millert Exp $";
+static char rcsid[] = "$OpenBSD: savecore.c,v 1.43 2007/09/11 15:25:14 gilles Exp $";
#endif
#endif /* not lint */
@@ -314,12 +314,9 @@ check_kmem(void)
if (strcmp(vers, core_vers) && kernel == 0) {
char *p;
- p = strchr(vers, '\n');
- if (p)
- *p = '\0';
- p = strchr(core_vers, '\n');
- if (p)
- *p = '\0';
+ vers[strcspn(vers, "\n")] = '\0';
+ core_vers[strcspn(core_vers, "\n")] = '\0';
+
syslog(LOG_WARNING,
"warning: %s version mismatch:\n\t%s\nand\t%s\n",
_PATH_UNIX, vers, core_vers);