From ad6dc08636347bbd8aebe3658eabf43dadb4aa90 Mon Sep 17 00:00:00 2001 From: brian Date: Thu, 18 Dec 1997 01:10:13 +0000 Subject: 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 --- usr.sbin/ppp/chat.c | 5 +++-- usr.sbin/ppp/command.c | 5 +++-- usr.sbin/ppp/modem.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'usr.sbin/ppp') 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 @@ -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); -- cgit v1.1