diff options
author | brian <brian@FreeBSD.org> | 1997-12-18 01:10:13 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-12-18 01:10:13 +0000 |
commit | ad6dc08636347bbd8aebe3658eabf43dadb4aa90 (patch) | |
tree | aafc13d009a2e0a3d0723158fd0477a09d74d91e | |
parent | 71fc17164f9d8dcc7f930336a677c5601e0255dd (diff) | |
download | FreeBSD-src-ad6dc08636347bbd8aebe3658eabf43dadb4aa90.zip FreeBSD-src-ad6dc08636347bbd8aebe3658eabf43dadb4aa90.tar.gz |
Replace
strcpy(a, b); /* a and b are the same size */
with
strncpy(a, b, sizeof(a));
a[sizeof(a)-1] = '\0';
Making the code `correct at a glance'.
Suggested by: Theo de Raadt <deraadt@cvs.openbsd.org>
-rw-r--r-- | usr.sbin/ppp/chat.c | 5 | ||||
-rw-r--r-- | usr.sbin/ppp/command.c | 5 | ||||
-rw-r--r-- | usr.sbin/ppp/modem.c | 5 |
3 files changed, 9 insertions, 6 deletions
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index 396927e..5026c37 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -18,7 +18,7 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.c,v 1.38 1997/11/09 14:18:36 brian Exp $ + * $Id: chat.c,v 1.39 1997/11/22 03:37:26 brian Exp $ * * TODO: * o Support more UUCP compatible control sequences. @@ -186,7 +186,8 @@ ExpandString(const char *str, char *result, int reslen, int sendmode) case 'T': if (VarAltPhone == NULL) { if (VarNextPhone == NULL) { - strcpy(VarPhoneCopy, VarPhoneList); + strncpy(VarPhoneCopy, VarPhoneList, sizeof(VarPhoneCopy)); + VarPhoneCopy[sizeof(VarPhoneCopy) - 1] = '\0'; VarNextPhone = VarPhoneCopy; } VarAltPhone = strsep(&VarNextPhone, ":"); diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index dc10681..ecab28c 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: command.c,v 1.112 1997/12/17 21:21:38 brian Exp $ + * $Id: command.c,v 1.113 1997/12/18 00:28:35 brian Exp $ * */ #include <sys/param.h> @@ -1360,7 +1360,8 @@ SetVariable(struct cmdargs const *arg) case VAR_PHONE: strncpy(VarPhoneList, argp, sizeof(VarPhoneList) - 1); VarPhoneList[sizeof(VarPhoneList) - 1] = '\0'; - strcpy(VarPhoneCopy, VarPhoneList); + strncpy(VarPhoneCopy, VarPhoneList, sizeof(VarPhoneCopy)); + VarPhoneCopy[sizeof(VarPhoneCopy) - 1] = '\0'; VarNextPhone = VarPhoneCopy; VarAltPhone = NULL; break; diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index cef758d..014dd8a 100644 --- a/usr.sbin/ppp/modem.c +++ b/usr.sbin/ppp/modem.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: modem.c,v 1.66 1997/11/18 14:52:06 brian Exp $ + * $Id: modem.c,v 1.67 1997/11/22 03:37:41 brian Exp $ * * TODO: */ @@ -680,7 +680,8 @@ HangupModem(int flag) if (modem >= 0) { char ScriptBuffer[SCRIPT_LEN]; - strcpy(ScriptBuffer, VarHangupScript); /* arrays are the same size */ + strncpy(ScriptBuffer, VarHangupScript, sizeof(ScriptBuffer)); + ScriptBuffer[sizeof(ScriptBuffer) - 1] = '\0'; LogPrintf(LogDEBUG, "HangupModem: Script: %s\n", ScriptBuffer); if (flag || !(mode & MODE_DEDICATED)) { DoChat(ScriptBuffer); |