summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1996-12-09 08:22:19 +0000
committerjkh <jkh@FreeBSD.org>1996-12-09 08:22:19 +0000
commit78cf4aee6b346217e9f9fbee836c6c67a8cbda61 (patch)
tree703f1957c7cb4d3138f4dca933a94c51a76a6ae6 /usr.sbin
parent316f6be0fa40f1f38890e5f7030d808f4de39e18 (diff)
downloadFreeBSD-src-78cf4aee6b346217e9f9fbee836c6c67a8cbda61.zip
FreeBSD-src-78cf4aee6b346217e9f9fbee836c6c67a8cbda61.tar.gz
As Paul has just pointed out, much of my strncpy() usage was either
bogus or overly complex and really needed to be done more consistently and sanely throughout - no question about it. Done. Suggested-By: Paul Traina <pst@Shockwave.COM>
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/sade/config.c6
-rw-r--r--usr.sbin/sade/devices.c4
-rw-r--r--usr.sbin/sade/dmenu.c4
-rw-r--r--usr.sbin/sade/label.c6
-rw-r--r--usr.sbin/sade/misc.c10
-rw-r--r--usr.sbin/sade/msg.c4
-rw-r--r--usr.sbin/sade/sade.h5
-rw-r--r--usr.sbin/sade/variable.c10
-rw-r--r--usr.sbin/sysinstall/anonFTP.c18
-rw-r--r--usr.sbin/sysinstall/config.c6
-rw-r--r--usr.sbin/sysinstall/devices.c4
-rw-r--r--usr.sbin/sysinstall/dmenu.c4
-rw-r--r--usr.sbin/sysinstall/index.c6
-rw-r--r--usr.sbin/sysinstall/label.c6
-rw-r--r--usr.sbin/sysinstall/media.c6
-rw-r--r--usr.sbin/sysinstall/misc.c10
-rw-r--r--usr.sbin/sysinstall/msg.c4
-rw-r--r--usr.sbin/sysinstall/network.c14
-rw-r--r--usr.sbin/sysinstall/sysinstall.h5
-rw-r--r--usr.sbin/sysinstall/tcpip.c40
-rw-r--r--usr.sbin/sysinstall/variable.c10
21 files changed, 102 insertions, 80 deletions
diff --git a/usr.sbin/sade/config.c b/usr.sbin/sade/config.c
index 7bdc5b9..ab4f062 100644
--- a/usr.sbin/sade/config.c
+++ b/usr.sbin/sade/config.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: config.c,v 1.60 1996/11/27 22:52:31 phk Exp $
+ * $Id: config.c,v 1.61 1996/12/02 05:01:00 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -275,7 +275,7 @@ configSysconfig(char *config)
/* Skip the comments */
if (lines[i][0] == '#')
continue;
- strcpy(tmp, lines[i]);
+ SAFE_STRCPY(tmp, lines[i]);
cp = index(tmp, '=');
if (!cp)
continue;
@@ -411,7 +411,7 @@ skip:
if (!index(hp, '.'))
cp2[0] = '\0';
else {
- strcpy(cp2, hp);
+ SAFE_STRCPY(cp2, hp);
*(index(cp2, '.')) = '\0';
}
fprintf(fp, "%s\t\t%s %s\n", cp, hp, cp2);
diff --git a/usr.sbin/sade/devices.c b/usr.sbin/sade/devices.c
index 56d9ec3..8965f6c 100644
--- a/usr.sbin/sade/devices.c
+++ b/usr.sbin/sade/devices.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: devices.c,v 1.51 1996/11/27 01:01:52 joerg Exp $
+ * $Id: devices.c,v 1.52 1996/12/08 12:27:53 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -102,7 +102,7 @@ new_device(char *name)
dev = safe_malloc(sizeof(Device));
bzero(dev, sizeof(Device));
if (name)
- strcpy(dev->name, name);
+ SAFE_STRCPY(dev->name, name);
return dev;
}
diff --git a/usr.sbin/sade/dmenu.c b/usr.sbin/sade/dmenu.c
index 410bd0b..9470f04 100644
--- a/usr.sbin/sade/dmenu.c
+++ b/usr.sbin/sade/dmenu.c
@@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated for what's essentially a complete rewrite.
*
- * $Id: dmenu.c,v 1.26 1996/11/07 08:03:21 jkh Exp $
+ * $Id: dmenu.c,v 1.27 1996/11/09 16:46:56 joerg Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -182,7 +182,7 @@ dmenuVarCheck(dialogMenuItem *item)
w = (char *)item->data;
if (!w)
return FALSE;
- strncpy(tmp, w, 256);
+ SAFE_STRCPY(tmp, w);
if ((cp = index(tmp, '=')) != NULL) {
*(cp++) = '\0';
if ((cp3 = index(cp, ',')) != NULL)
diff --git a/usr.sbin/sade/label.c b/usr.sbin/sade/label.c
index 87a2313..28c670e 100644
--- a/usr.sbin/sade/label.c
+++ b/usr.sbin/sade/label.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: label.c,v 1.62 1996/10/04 14:53:52 jkh Exp $
+ * $Id: label.c,v 1.63 1996/10/06 11:40:31 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -248,7 +248,7 @@ new_part(char *mpoint, Boolean newfs, u_long size)
mpoint = "/change_me";
ret = (PartInfo *)safe_malloc(sizeof(PartInfo));
- strncpy(ret->mountpoint, mpoint, FILENAME_MAX);
+ sstrncpy(ret->mountpoint, mpoint, FILENAME_MAX);
strcpy(ret->newfs_cmd, "newfs -b 8192 -f 1024");
ret->newfs = newfs;
if (!size)
@@ -355,7 +355,7 @@ getNewfsCmd(PartInfo *p)
"Please enter the newfs command and options you'd like to use in\n"
"creating this file system.");
if (val)
- strncpy(p->newfs_cmd, val, NEWFS_CMD_MAX);
+ sstrncpy(p->newfs_cmd, val, NEWFS_CMD_MAX);
}
#define MAX_MOUNT_NAME 12
diff --git a/usr.sbin/sade/misc.c b/usr.sbin/sade/misc.c
index 1dfc30d..17ce8eb 100644
--- a/usr.sbin/sade/misc.c
+++ b/usr.sbin/sade/misc.c
@@ -1,7 +1,7 @@
/*
* Miscellaneous support routines..
*
- * $Id: misc.c,v 1.21 1996/07/08 08:54:30 jkh Exp $
+ * $Id: misc.c,v 1.22 1996/07/09 14:28:17 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -76,6 +76,14 @@ string_concat(char *one, char *two)
return tmp;
}
+/* sane strncpy() function */
+char *
+sstrncpy(char *dst, const char *src, int size)
+{
+ *(dst + size) = '\0';
+ return strncpy(dst, src, size - 1);
+}
+
/* Concatenate three strings into static storage */
char *
string_concat3(char *one, char *two, char *three)
diff --git a/usr.sbin/sade/msg.c b/usr.sbin/sade/msg.c
index ee79777..7770c70 100644
--- a/usr.sbin/sade/msg.c
+++ b/usr.sbin/sade/msg.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: msg.c,v 1.40 1996/08/03 10:11:21 jkh Exp $
+ * $Id: msg.c,v 1.41 1996/10/01 04:56:34 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -257,7 +257,7 @@ msgGetInput(char *buf, char *fmt, ...)
use_helpline(NULL);
use_helpfile(NULL);
if (buf)
- strcpy(input_buffer, buf);
+ SAFE_STRCPY(input_buffer, buf);
else
input_buffer[0] = '\0';
if (OnVTY) {
diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h
index ddc94e2..dab2d63 100644
--- a/usr.sbin/sade/sade.h
+++ b/usr.sbin/sade/sade.h
@@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
- * $Id: sysinstall.h,v 1.88 1996/12/09 06:02:31 jkh Exp $
+ * $Id: sysinstall.h,v 1.89 1996/12/09 06:37:45 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -147,6 +147,8 @@
#define ATTR_SELECTED (ColorDisplay ? item_selected_attr : item_attr)
#define ATTR_TITLE button_active_attr
+/* Handy strncpy() macro */
+#define SAFE_STRCPY(to, from) sstrncpy((to), (from), sizeof (to))
/*** Types ***/
typedef unsigned int Boolean;
@@ -564,6 +566,7 @@ extern int Mkdir(char *);
extern int Mount(char *, void *data);
extern WINDOW *savescr(void);
extern void restorescr(WINDOW *w);
+extern char *sstrncpy(char *dst, const char *src, int size);
/* msg.c */
extern Boolean isDebug(void);
diff --git a/usr.sbin/sade/variable.c b/usr.sbin/sade/variable.c
index 7d77d15..013358e 100644
--- a/usr.sbin/sade/variable.c
+++ b/usr.sbin/sade/variable.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: variable.c,v 1.10 1996/04/29 06:47:10 jkh Exp $
+ * $Id: variable.c,v 1.11 1996/06/12 14:02:13 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -51,15 +51,15 @@ make_variable(char *var, char *value)
if (!strcmp(newvar->name, var)) {
if (isDebug())
msgDebug("variable %s was %s, now %s\n", newvar->name, newvar->value, value);
- strncpy(newvar->value, value, VAR_VALUE_MAX);
+ SAFE_STRCPY(newvar->value, value);
return;
}
}
/* No? Create a new one */
newvar = (Variable *)safe_malloc(sizeof(Variable));
- strncpy(newvar->name, var, VAR_NAME_MAX);
- strncpy(newvar->value, value, VAR_VALUE_MAX);
+ SAFE_STRCPY(newvar->name, var);
+ SAFE_STRCPY(newvar->value, value);
newvar->next = VarHead;
VarHead = newvar;
if (isDebug())
@@ -75,7 +75,7 @@ variable_set(char *var)
msgFatal("NULL variable name & value passed.");
else if (!*var)
msgDebug("Warning: Zero length name & value passed to variable_set()\n");
- strncpy(tmp, var, VAR_NAME_MAX + VAR_VALUE_MAX);
+ SAFE_STRCPY(tmp, var);
if ((cp = index(tmp, '=')) == NULL)
msgFatal("Invalid variable format: %s", var);
*(cp++) = '\0';
diff --git a/usr.sbin/sysinstall/anonFTP.c b/usr.sbin/sysinstall/anonFTP.c
index 20e26b3..cdd40fc 100644
--- a/usr.sbin/sysinstall/anonFTP.c
+++ b/usr.sbin/sysinstall/anonFTP.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: anonFTP.c,v 1.16 1996/09/01 08:17:12 jkh Exp $
+ * $Id: anonFTP.c,v 1.17 1996/09/06 05:58:27 jkh Exp $
*
* Copyright (c) 1995
* Coranth Gryphon. All rights reserved.
@@ -179,7 +179,7 @@ createFtpUser(void)
tptr = msgGetInput("14", "What group name to use for gid %d ?", gid);
if (tptr && *tptr) {
- strcpy(tconf.group, tptr);
+ SAFE_STRCPY(tconf.group, tptr);
if ((tgrp = getgrnam(tconf.group))) {
gid = tgrp->gr_gid;
}
@@ -250,10 +250,10 @@ anonftpOpenDialog(void)
bzero(&tconf, sizeof(tconf));
- strcpy(tconf.group, FTP_GROUP);
- strcpy(tconf.upload, FTP_UPLOAD);
- strcpy(tconf.comment, FTP_COMMENT);
- strcpy(tconf.homedir, FTP_HOMEDIR);
+ SAFE_STRCPY(tconf.group, FTP_GROUP);
+ SAFE_STRCPY(tconf.upload, FTP_UPLOAD);
+ SAFE_STRCPY(tconf.comment, FTP_COMMENT);
+ SAFE_STRCPY(tconf.homedir, FTP_HOMEDIR);
sprintf(tconf.uid, "%d", FTP_UID);
/* Loop over the layout list, create the objects, and add them
@@ -389,10 +389,10 @@ configAnonFTP(dialogMenuItem *self)
sprintf(tconf.uid, "%d", FTP_UID);
if (!tconf.group[0])
- strcpy(tconf.group, FTP_GROUP);
+ SAFE_STRCPY(tconf.group, FTP_GROUP);
if (!tconf.upload[0])
- strcpy(tconf.upload, FTP_UPLOAD);
+ SAFE_STRCPY(tconf.upload, FTP_UPLOAD);
/*** If the user did not specify a directory, use default ***/
@@ -400,7 +400,7 @@ configAnonFTP(dialogMenuItem *self)
tconf.homedir[strlen(tconf.homedir) - 1] = '\0';
if (!tconf.homedir[0])
- strcpy(tconf.homedir, FTP_HOMEDIR);
+ SAFE_STRCPY(tconf.homedir, FTP_HOMEDIR);
/*** If HomeDir does not exist, create it ***/
diff --git a/usr.sbin/sysinstall/config.c b/usr.sbin/sysinstall/config.c
index 7bdc5b9..ab4f062 100644
--- a/usr.sbin/sysinstall/config.c
+++ b/usr.sbin/sysinstall/config.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: config.c,v 1.60 1996/11/27 22:52:31 phk Exp $
+ * $Id: config.c,v 1.61 1996/12/02 05:01:00 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -275,7 +275,7 @@ configSysconfig(char *config)
/* Skip the comments */
if (lines[i][0] == '#')
continue;
- strcpy(tmp, lines[i]);
+ SAFE_STRCPY(tmp, lines[i]);
cp = index(tmp, '=');
if (!cp)
continue;
@@ -411,7 +411,7 @@ skip:
if (!index(hp, '.'))
cp2[0] = '\0';
else {
- strcpy(cp2, hp);
+ SAFE_STRCPY(cp2, hp);
*(index(cp2, '.')) = '\0';
}
fprintf(fp, "%s\t\t%s %s\n", cp, hp, cp2);
diff --git a/usr.sbin/sysinstall/devices.c b/usr.sbin/sysinstall/devices.c
index 56d9ec3..8965f6c 100644
--- a/usr.sbin/sysinstall/devices.c
+++ b/usr.sbin/sysinstall/devices.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: devices.c,v 1.51 1996/11/27 01:01:52 joerg Exp $
+ * $Id: devices.c,v 1.52 1996/12/08 12:27:53 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -102,7 +102,7 @@ new_device(char *name)
dev = safe_malloc(sizeof(Device));
bzero(dev, sizeof(Device));
if (name)
- strcpy(dev->name, name);
+ SAFE_STRCPY(dev->name, name);
return dev;
}
diff --git a/usr.sbin/sysinstall/dmenu.c b/usr.sbin/sysinstall/dmenu.c
index 410bd0b..9470f04 100644
--- a/usr.sbin/sysinstall/dmenu.c
+++ b/usr.sbin/sysinstall/dmenu.c
@@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated for what's essentially a complete rewrite.
*
- * $Id: dmenu.c,v 1.26 1996/11/07 08:03:21 jkh Exp $
+ * $Id: dmenu.c,v 1.27 1996/11/09 16:46:56 joerg Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -182,7 +182,7 @@ dmenuVarCheck(dialogMenuItem *item)
w = (char *)item->data;
if (!w)
return FALSE;
- strncpy(tmp, w, 256);
+ SAFE_STRCPY(tmp, w);
if ((cp = index(tmp, '=')) != NULL) {
*(cp++) = '\0';
if ((cp3 = index(cp, ',')) != NULL)
diff --git a/usr.sbin/sysinstall/index.c b/usr.sbin/sysinstall/index.c
index 4c5d144..62bcc0e 100644
--- a/usr.sbin/sysinstall/index.c
+++ b/usr.sbin/sysinstall/index.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: index.c,v 1.37 1996/08/01 12:02:24 jkh Exp $
+ * $Id: index.c,v 1.38 1996/08/03 10:10:54 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -491,7 +491,7 @@ index_menu(PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll)
char buf[256];
/* Brutally adjust description to fit in menu */
- strcpy(buf, kp->desc);
+ SAFE_STRCPY(buf, kp->desc);
if (strlen(buf) > (_MAX_DESC - maxname))
buf[_MAX_DESC - maxname] = '\0';
nitems = item_add(nitems, kp->name, buf, pkg_checked, pkg_fire, pkg_selected, kp, (int)plist, &curr, &max);
@@ -555,7 +555,7 @@ index_extract_one(Device *dev, PkgNodePtr top, PkgNodePtr who, Boolean depended)
if (id && id->deps && strlen(id->deps)) {
char t[1024], *cp, *cp2;
- strcpy(t, id->deps);
+ SAFE_STRCPY(t, id->deps);
cp = t;
while (cp && DITEM_STATUS(status) == DITEM_SUCCESS) {
if ((cp2 = index(cp, ' ')) != NULL)
diff --git a/usr.sbin/sysinstall/label.c b/usr.sbin/sysinstall/label.c
index 87a2313..28c670e 100644
--- a/usr.sbin/sysinstall/label.c
+++ b/usr.sbin/sysinstall/label.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: label.c,v 1.62 1996/10/04 14:53:52 jkh Exp $
+ * $Id: label.c,v 1.63 1996/10/06 11:40:31 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -248,7 +248,7 @@ new_part(char *mpoint, Boolean newfs, u_long size)
mpoint = "/change_me";
ret = (PartInfo *)safe_malloc(sizeof(PartInfo));
- strncpy(ret->mountpoint, mpoint, FILENAME_MAX);
+ sstrncpy(ret->mountpoint, mpoint, FILENAME_MAX);
strcpy(ret->newfs_cmd, "newfs -b 8192 -f 1024");
ret->newfs = newfs;
if (!size)
@@ -355,7 +355,7 @@ getNewfsCmd(PartInfo *p)
"Please enter the newfs command and options you'd like to use in\n"
"creating this file system.");
if (val)
- strncpy(p->newfs_cmd, val, NEWFS_CMD_MAX);
+ sstrncpy(p->newfs_cmd, val, NEWFS_CMD_MAX);
}
#define MAX_MOUNT_NAME 12
diff --git a/usr.sbin/sysinstall/media.c b/usr.sbin/sysinstall/media.c
index efa9bc6..673baba 100644
--- a/usr.sbin/sysinstall/media.c
+++ b/usr.sbin/sysinstall/media.c
@@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
- * $Id: media.c,v 1.64 1996/11/04 02:12:49 jkh Exp $
+ * $Id: media.c,v 1.65 1996/11/07 14:17:09 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -297,7 +297,7 @@ mediaSetFTP(dialogMenuItem *self)
variable_unset(VAR_FTP_PATH);
return DITEM_FAILURE | what;
}
- strcpy(ftpDevice.name, cp);
+ SAFE_STRCPY(ftpDevice.name, cp);
dialog_clear_norefresh();
if (RunningAsInit &&
@@ -409,7 +409,7 @@ mediaSetNFS(dialogMenuItem *self)
"host:/full/pathname/to/FreeBSD/distdir");
return DITEM_FAILURE;
}
- strncpy(nfsDevice.name, cp, DEV_NAME_MAX);
+ SAFE_STRCPY(nfsDevice.name, cp);
/* str == NULL means we were just called to change NFS paths, not network interfaces */
if (!tcpDeviceSelect())
return DITEM_FAILURE;
diff --git a/usr.sbin/sysinstall/misc.c b/usr.sbin/sysinstall/misc.c
index 1dfc30d..17ce8eb 100644
--- a/usr.sbin/sysinstall/misc.c
+++ b/usr.sbin/sysinstall/misc.c
@@ -1,7 +1,7 @@
/*
* Miscellaneous support routines..
*
- * $Id: misc.c,v 1.21 1996/07/08 08:54:30 jkh Exp $
+ * $Id: misc.c,v 1.22 1996/07/09 14:28:17 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -76,6 +76,14 @@ string_concat(char *one, char *two)
return tmp;
}
+/* sane strncpy() function */
+char *
+sstrncpy(char *dst, const char *src, int size)
+{
+ *(dst + size) = '\0';
+ return strncpy(dst, src, size - 1);
+}
+
/* Concatenate three strings into static storage */
char *
string_concat3(char *one, char *two, char *three)
diff --git a/usr.sbin/sysinstall/msg.c b/usr.sbin/sysinstall/msg.c
index ee79777..7770c70 100644
--- a/usr.sbin/sysinstall/msg.c
+++ b/usr.sbin/sysinstall/msg.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: msg.c,v 1.40 1996/08/03 10:11:21 jkh Exp $
+ * $Id: msg.c,v 1.41 1996/10/01 04:56:34 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -257,7 +257,7 @@ msgGetInput(char *buf, char *fmt, ...)
use_helpline(NULL);
use_helpfile(NULL);
if (buf)
- strcpy(input_buffer, buf);
+ SAFE_STRCPY(input_buffer, buf);
else
input_buffer[0] = '\0';
if (OnVTY) {
diff --git a/usr.sbin/sysinstall/network.c b/usr.sbin/sysinstall/network.c
index 0b20b12..a7ed90f 100644
--- a/usr.sbin/sysinstall/network.c
+++ b/usr.sbin/sysinstall/network.c
@@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
- * $Id: network.c,v 1.19 1996/12/09 06:37:44 jkh Exp $
+ * $Id: network.c,v 1.20 1996/12/09 06:45:03 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -94,7 +94,7 @@ mediaInitNetwork(Device *dev)
if (!val)
return FALSE;
else
- strncpy(attach, val, 256);
+ SAFE_STRCPY(attach, val);
/*
* Doing this with vsystem() is actually bogus since we should be storing the pid of slattach
* for later killing. It's just too convenient to call vsystem(), however, rather than
@@ -198,15 +198,17 @@ startPPP(Device *devp)
"maximum data rate since most modems can talk at one speed to the\n"
"computer and at another speed to the remote end.\n\n"
"If you're not sure what to put here, just select the default.");
- strncpy(speed, (val && *val) ? val : "115200", 16);
+ SAFE_STRCPY(speed, (val && *val) ? val : "115200");
+
+ val = variable_get(VAR_GATEWAY);
+ SAFE_STRCPY(provider, (val && *val) ? val : "0");
- strncpy(provider, variable_get(VAR_GATEWAY) ? variable_get(VAR_GATEWAY) : "0", 16);
val = msgGetInput(provider, "Enter the IP address of your service provider or 0 if you\n"
"don't know it and would prefer to negotiate it dynamically.");
- strncpy(provider, val ? val : "0", 16);
+ SAFE_STRCPY(provider, (val && *val) ? val : "0");
if (devp->private && ((DevInfo *)devp->private)->ipaddr[0])
- strncpy(myaddr, ((DevInfo *)devp->private)->ipaddr, 16);
+ SAFE_STRCPY(myaddr, ((DevInfo *)devp->private)->ipaddr);
else
strcpy(myaddr, "0");
diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h
index ddc94e2..dab2d63 100644
--- a/usr.sbin/sysinstall/sysinstall.h
+++ b/usr.sbin/sysinstall/sysinstall.h
@@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
- * $Id: sysinstall.h,v 1.88 1996/12/09 06:02:31 jkh Exp $
+ * $Id: sysinstall.h,v 1.89 1996/12/09 06:37:45 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -147,6 +147,8 @@
#define ATTR_SELECTED (ColorDisplay ? item_selected_attr : item_attr)
#define ATTR_TITLE button_active_attr
+/* Handy strncpy() macro */
+#define SAFE_STRCPY(to, from) sstrncpy((to), (from), sizeof (to))
/*** Types ***/
typedef unsigned int Boolean;
@@ -564,6 +566,7 @@ extern int Mkdir(char *);
extern int Mount(char *, void *data);
extern WINDOW *savescr(void);
extern void restorescr(WINDOW *w);
+extern char *sstrncpy(char *dst, const char *src, int size);
/* msg.c */
extern Boolean isDebug(void);
diff --git a/usr.sbin/sysinstall/tcpip.c b/usr.sbin/sysinstall/tcpip.c
index a774c6d..a8c10fc 100644
--- a/usr.sbin/sysinstall/tcpip.c
+++ b/usr.sbin/sysinstall/tcpip.c
@@ -1,5 +1,5 @@
/*
- * $Id: tcpip.c,v 1.49 1996/11/07 08:03:29 jkh Exp $
+ * $Id: tcpip.c,v 1.50 1996/12/09 06:37:46 jkh Exp $
*
* Copyright (c) 1995
* Gary J Palmer. All rights reserved.
@@ -210,51 +210,51 @@ tcpOpenDialog(Device *devp)
if (devp->private) {
DevInfo *di = (DevInfo *)devp->private;
- strcpy(ipaddr, di->ipaddr);
- strcpy(netmask, di->netmask);
- strcpy(extras, di->extras);
+ SAFE_STRCPY(ipaddr, di->ipaddr);
+ SAFE_STRCPY(netmask, di->netmask);
+ SAFE_STRCPY(extras, di->extras);
}
else { /* See if there are any defaults */
char *cp;
if (!ipaddr[0]) {
if ((cp = variable_get(VAR_IPADDR)) != NULL)
- strcpy(ipaddr, cp);
+ SAFE_STRCPY(ipaddr, cp);
else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_IPADDR))) != NULL)
- strcpy(ipaddr, cp);
+ SAFE_STRCPY(ipaddr, cp);
}
if (!netmask[0]) {
if ((cp = variable_get(VAR_NETMASK)) != NULL)
- strcpy(netmask, cp);
+ SAFE_STRCPY(netmask, cp);
else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_NETMASK))) != NULL)
- strcpy(netmask, cp);
+ SAFE_STRCPY(netmask, cp);
}
if (!extras[0]) {
if ((cp = variable_get(VAR_EXTRAS)) != NULL)
- strcpy(extras, cp);
+ SAFE_STRCPY(extras, cp);
else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_EXTRAS))) != NULL)
- strcpy(extras, cp);
+ SAFE_STRCPY(extras, cp);
}
}
/* Look up values already recorded with the system, or blank the string variables ready to accept some new data */
tmp = variable_get(VAR_HOSTNAME);
if (tmp)
- strcpy(hostname, tmp);
+ SAFE_STRCPY(hostname, tmp);
else
bzero(hostname, sizeof(hostname));
tmp = variable_get(VAR_DOMAINNAME);
if (tmp)
- strcpy(domainname, tmp);
+ SAFE_STRCPY(domainname, tmp);
else
bzero(domainname, sizeof(domainname));
tmp = variable_get(VAR_GATEWAY);
if (tmp)
- strcpy(gateway, tmp);
+ SAFE_STRCPY(gateway, tmp);
else
bzero(gateway, sizeof(gateway));
tmp = variable_get(VAR_NAMESERVER);
if (tmp)
- strcpy(nameserver, tmp);
+ SAFE_STRCPY(nameserver, tmp);
else
bzero(nameserver, sizeof(nameserver));
@@ -314,8 +314,7 @@ tcpOpenDialog(Device *devp)
if (n == LAYOUT_HOSTNAME) {
/* We are in the Hostname field - calculate the domainname */
if ((tmp = index(hostname, '.')) != NULL) {
- strncpy(domainname, tmp + 1, strlen(tmp + 1));
- domainname[strlen(tmp+1)] = '\0';
+ sstrncpy(domainname, tmp + 1, strlen(tmp + 1));
RefreshStringObj(layout[LAYOUT_DOMAINNAME].obj);
}
}
@@ -385,8 +384,7 @@ tcpOpenDialog(Device *devp)
/* BODGE ALERT! */
if (((tmp = index(hostname, '.')) != NULL) && (strlen(domainname)==0)) {
- strncpy(domainname, tmp + 1, strlen(tmp + 1));
- domainname[strlen(tmp+1)] = '\0';
+ sstrncpy(domainname, tmp + 1, strlen(tmp + 1));
RefreshStringObj(layout[1].obj);
}
}
@@ -416,9 +414,9 @@ tcpOpenDialog(Device *devp)
if (!devp->private)
devp->private = (DevInfo *)safe_malloc(sizeof(DevInfo));
di = devp->private;
- strcpy(di->ipaddr, ipaddr);
- strcpy(di->netmask, netmask);
- strcpy(di->extras, extras);
+ SAFE_STRCPY(di->ipaddr, ipaddr);
+ SAFE_STRCPY(di->netmask, netmask);
+ SAFE_STRCPY(di->extras, extras);
sprintf(temp, "inet %s %s netmask %s", ipaddr, extras, netmask);
sprintf(ifn, "%s%s", VAR_IFCONFIG, devp->name);
diff --git a/usr.sbin/sysinstall/variable.c b/usr.sbin/sysinstall/variable.c
index 7d77d15..013358e 100644
--- a/usr.sbin/sysinstall/variable.c
+++ b/usr.sbin/sysinstall/variable.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: variable.c,v 1.10 1996/04/29 06:47:10 jkh Exp $
+ * $Id: variable.c,v 1.11 1996/06/12 14:02:13 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -51,15 +51,15 @@ make_variable(char *var, char *value)
if (!strcmp(newvar->name, var)) {
if (isDebug())
msgDebug("variable %s was %s, now %s\n", newvar->name, newvar->value, value);
- strncpy(newvar->value, value, VAR_VALUE_MAX);
+ SAFE_STRCPY(newvar->value, value);
return;
}
}
/* No? Create a new one */
newvar = (Variable *)safe_malloc(sizeof(Variable));
- strncpy(newvar->name, var, VAR_NAME_MAX);
- strncpy(newvar->value, value, VAR_VALUE_MAX);
+ SAFE_STRCPY(newvar->name, var);
+ SAFE_STRCPY(newvar->value, value);
newvar->next = VarHead;
VarHead = newvar;
if (isDebug())
@@ -75,7 +75,7 @@ variable_set(char *var)
msgFatal("NULL variable name & value passed.");
else if (!*var)
msgDebug("Warning: Zero length name & value passed to variable_set()\n");
- strncpy(tmp, var, VAR_NAME_MAX + VAR_VALUE_MAX);
+ SAFE_STRCPY(tmp, var);
if ((cp = index(tmp, '=')) == NULL)
msgFatal("Invalid variable format: %s", var);
*(cp++) = '\0';
OpenPOWER on IntegriCloud