diff options
author | lebel <lebel@cvs.openbsd.org> | 2001-06-26 23:44:01 +0000 |
---|---|---|
committer | lebel <lebel@cvs.openbsd.org> | 2001-06-26 23:44:01 +0000 |
commit | 7b2ba79532756a71a9857a4586e2c8878124fc31 (patch) | |
tree | 62c06b94ff971f756274ac59ed3553f8e7cd5869 | |
parent | 42433f64b2ae54195a56e78021b6672732eddd82 (diff) |
use strlcpy vs strncpy+a[len-1]='\0'. millert@ ok.
-rw-r--r-- | usr.bin/ftp/cmds.c | 27 | ||||
-rw-r--r-- | usr.bin/ftp/complete.c | 19 | ||||
-rw-r--r-- | usr.bin/ftp/ftp.c | 27 |
3 files changed, 27 insertions, 46 deletions
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c index a75a1fd7646..7c863daad36 100644 --- a/usr.bin/ftp/cmds.c +++ b/usr.bin/ftp/cmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmds.c,v 1.35 2000/12/24 00:29:00 aaron Exp $ */ +/* $OpenBSD: cmds.c,v 1.36 2001/06/26 23:43:59 lebel Exp $ */ /* $NetBSD: cmds.c,v 1.27 1997/08/18 10:20:15 lukem Exp $ */ /* @@ -67,7 +67,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$OpenBSD: cmds.c,v 1.35 2000/12/24 00:29:00 aaron Exp $"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.36 2001/06/26 23:43:59 lebel Exp $"; #endif #endif /* not lint */ @@ -937,8 +937,7 @@ setgate(argc, argv) gateport = strdup(argv[2]); #endif } - strncpy(gsbuf, argv[1], sizeof(gsbuf) - 1); - gsbuf[sizeof(gsbuf) - 1] = '\0'; + strlcpy(gsbuf, argv[1], sizeof(gsbuf)); gateserver = gsbuf; gatemode = 1; } @@ -1286,8 +1285,7 @@ shell(argc, argv) if (namep == NULL) namep = shell; shellnam[0] = '-'; - (void)strncpy(shellnam + 1, ++namep, sizeof(shellnam) - 2); - shellnam[sizeof(shellnam) - 1] = '\0'; + (void)strlcpy(shellnam + 1, ++namep, sizeof(shellnam) - 1); if (strcmp(namep, "sh") != 0) shellnam[0] = '+'; if (debug) { @@ -1496,8 +1494,7 @@ quote1(initial, argc, argv) int i, len; char buf[BUFSIZ]; /* must be >= sizeof(line) */ - (void)strncpy(buf, initial, sizeof(buf) - 1); - buf[sizeof(buf) - 1] = '\0'; + (void)strlcpy(buf, initial, sizeof(buf)); if (argc > 1) { for (i = 1, len = strlen(buf); i < argc && len < sizeof(buf)-1; i++) { @@ -1514,8 +1511,7 @@ quote1(initial, argc, argv) break; /* Copy next argument, NUL terminate always */ - strncpy(&buf[len], argv[i], sizeof(buf) - len - 1); - buf[sizeof(buf) - 1] = '\0'; + strlcpy(&buf[len], argv[i], sizeof(buf) - len); /* Update string length */ len = strlen(buf); @@ -1761,14 +1757,12 @@ setntrans(argc, argv) } ntflag++; code = ntflag; - (void)strncpy(ntin, argv[1], sizeof(ntin) - 1); - ntin[sizeof(ntin) - 1] = '\0'; + (void)strlcpy(ntin, argv[1], sizeof(ntin)); if (argc == 2) { ntout[0] = '\0'; return; } - (void)strncpy(ntout, argv[2], sizeof(ntout) - 1); - ntout[sizeof(ntout) - 1] = '\0'; + (void)strlcpy(ntout, argv[2], sizeof(ntout)); } char * @@ -2111,9 +2105,8 @@ macdef(argc, argv) if (interactive) fputs( "Enter macro line by line, terminating it with a null line.\n", ttyout); - (void)strncpy(macros[macnum].mac_name, argv[1], - sizeof(macros[macnum].mac_name) - 1); - macros[macnum].mac_name[sizeof(macros[macnum].mac_name) - 1] = '\0'; + (void)strlcpy(macros[macnum].mac_name, argv[1], + sizeof(macros[macnum].mac_name)); if (macnum == 0) macros[macnum].mac_start = macbuf; else diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c index ba5f02e6d85..7c35659a986 100644 --- a/usr.bin/ftp/complete.c +++ b/usr.bin/ftp/complete.c @@ -1,4 +1,4 @@ -/* $OpenBSD: complete.c,v 1.10 2001/03/09 17:01:02 millert Exp $ */ +/* $OpenBSD: complete.c,v 1.11 2001/06/26 23:44:00 lebel Exp $ */ /* $NetBSD: complete.c,v 1.10 1997/08/18 10:20:18 lukem Exp $ */ /*- @@ -39,7 +39,7 @@ #ifndef SMALL #ifndef lint -static char rcsid[] = "$OpenBSD: complete.c,v 1.10 2001/03/09 17:01:02 millert Exp $"; +static char rcsid[] = "$OpenBSD: complete.c,v 1.11 2001/06/26 23:44:00 lebel Exp $"; #endif /* not lint */ /* @@ -113,8 +113,7 @@ complete_ambiguous(word, list, words) matchlen = j; } if (matchlen > wordlen) { - (void)strncpy(insertstr, lastmatch, matchlen); - insertstr[matchlen] = '\0'; + (void)strlcpy(insertstr, lastmatch, matchlen+1); if (el_insertstr(el, insertstr + wordlen) == -1) return (CC_ERROR); else @@ -183,8 +182,7 @@ complete_local(word, list) dir[0] = '/'; dir[1] = '\0'; } else { - (void)strncpy(dir, word, (size_t)(file - word)); - dir[file - word] = '\0'; + (void)strlcpy(dir, word, (size_t)(file - word) + 1); } file++; } @@ -241,8 +239,7 @@ complete_remote(word, list) cp = file; while (*cp == '/' && cp > word) cp--; - (void)strncpy(dir, word, (size_t)(cp - word + 1)); - dir[cp - word + 1] = '\0'; + (void)strlcpy(dir, word, (size_t)(cp - word + 2)); file++; } @@ -317,8 +314,7 @@ complete(el, ch) len = lf->lastchar - lf->buffer; if (len >= sizeof(line)) return (CC_ERROR); - (void)strncpy(line, lf->buffer, len); - line[len] = '\0'; + (void)strlcpy(line, lf->buffer, len+1); cursor_pos = line + (lf->cursor - lf->buffer); lastc_argc = cursor_argc; /* remember last cursor pos */ lastc_argo = cursor_argo; @@ -333,8 +329,7 @@ complete(el, ch) && strncmp(word, margv[cursor_argc], cursor_argo) == 0) dolist = 1; else - (void)strncpy(word, margv[cursor_argc], cursor_argo); - word[cursor_argo] = '\0'; + (void)strlcpy(word, margv[cursor_argc], cursor_argo+1); if (cursor_argc == 0) return (complete_command(word, dolist)); diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c index 46795071279..c2310f829cd 100644 --- a/usr.bin/ftp/ftp.c +++ b/usr.bin/ftp/ftp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftp.c,v 1.40 2001/06/23 22:48:44 millert Exp $ */ +/* $OpenBSD: ftp.c,v 1.41 2001/06/26 23:44:00 lebel Exp $ */ /* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */ /* @@ -67,7 +67,7 @@ #if 0 static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94"; #else -static char rcsid[] = "$OpenBSD: ftp.c,v 1.40 2001/06/23 22:48:44 millert Exp $"; +static char rcsid[] = "$OpenBSD: ftp.c,v 1.41 2001/06/26 23:44:00 lebel Exp $"; #endif #endif /* not lint */ @@ -174,10 +174,9 @@ hookup(host, port) } if (res0->ai_canonname) - strncpy(hostnamebuf, res0->ai_canonname, sizeof(hostnamebuf)); + strlcpy(hostnamebuf, res0->ai_canonname, sizeof(hostnamebuf)); else - strncpy(hostnamebuf, host, sizeof(hostnamebuf)); - hostnamebuf[sizeof(hostnamebuf) - 1] = '\0'; + strlcpy(hostnamebuf, host, sizeof(hostnamebuf)); hostname = hostnamebuf; s = -1; @@ -453,8 +452,7 @@ getreply(expecteof) if (len > sizeof(reply_string)) len = sizeof(reply_string); - (void)strncpy(reply_string, current_line, len); - reply_string[len] = '\0'; + (void)strlcpy(reply_string, current_line, len + 1); } if (continuation && code != originalcode) { if (originalcode == 0) @@ -1638,8 +1636,7 @@ pswitch(flag) ip->connect = connected; connected = op->connect; if (hostname) { - (void)strncpy(ip->name, hostname, sizeof(ip->name) - 1); - ip->name[sizeof(ip->name) - 1] = '\0'; + (void)strlcpy(ip->name, hostname, sizeof(ip->name)); } else ip->name[0] = '\0'; hostname = op->name; @@ -1665,19 +1662,15 @@ pswitch(flag) mcase = op->mcse; ip->ntflg = ntflag; ntflag = op->ntflg; - (void)strncpy(ip->nti, ntin, sizeof(ip->nti) - 1); - (ip->nti)[sizeof(ip->nti) - 1] = '\0'; + (void)strlcpy(ip->nti, ntin, sizeof(ip->nti)); (void)strcpy(ntin, op->nti); - (void)strncpy(ip->nto, ntout, sizeof(ip->nto) - 1); - (ip->nto)[sizeof(ip->nto) - 1] = '\0'; + (void)strlcpy(ip->nto, ntout, sizeof(ip->nto)); (void)strcpy(ntout, op->nto); ip->mapflg = mapflag; mapflag = op->mapflg; - (void)strncpy(ip->mi, mapin, sizeof(ip->mi) - 1); - (ip->mi)[sizeof(ip->mi) - 1] = '\0'; + (void)strlcpy(ip->mi, mapin, sizeof(ip->mi)); (void)strcpy(mapin, op->mi); - (void)strncpy(ip->mo, mapout, sizeof(ip->mo) - 1); - (ip->mo)[sizeof(ip->mo) - 1] = '\0'; + (void)strlcpy(ip->mo, mapout, sizeof(ip->mo)); (void)strcpy(mapout, op->mo); (void)signal(SIGINT, oldintr); if (abrtflag) { |