diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-04 20:25:08 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-04 20:25:08 +0000 |
commit | 96eef4873443f17a48dc476e38e0ce7c3dfb7af1 (patch) | |
tree | a0074d08345d60f73dbe2cb4389526f43ddf57ee /usr.sbin/pppd | |
parent | 87bb416d9162030904882f8dc0b054ecc84f194c (diff) |
strlcpy and snprintf; various people ok
Diffstat (limited to 'usr.sbin/pppd')
-rw-r--r-- | usr.sbin/pppd/auth.c | 18 | ||||
-rw-r--r-- | usr.sbin/pppd/ccp.c | 17 | ||||
-rw-r--r-- | usr.sbin/pppd/chap.c | 8 | ||||
-rw-r--r-- | usr.sbin/pppd/ipcp.c | 14 | ||||
-rw-r--r-- | usr.sbin/pppd/ipxcp.c | 33 | ||||
-rw-r--r-- | usr.sbin/pppd/main.c | 27 | ||||
-rw-r--r-- | usr.sbin/pppd/options.c | 27 | ||||
-rw-r--r-- | usr.sbin/pppd/sys-bsd.c | 10 |
8 files changed, 69 insertions, 85 deletions
diff --git a/usr.sbin/pppd/auth.c b/usr.sbin/pppd/auth.c index c77564659ac..99b0a8c3ac3 100644 --- a/usr.sbin/pppd/auth.c +++ b/usr.sbin/pppd/auth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth.c,v 1.26 2003/02/18 13:14:43 jmc Exp $ */ +/* $OpenBSD: auth.c,v 1.27 2003/04/04 20:25:07 deraadt Exp $ */ /* * auth.c - PPP authentication and phase control. @@ -77,7 +77,7 @@ #if 0 static char rcsid[] = "Id: auth.c,v 1.37 1998/03/26 04:46:03 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: auth.c,v 1.26 2003/02/18 13:14:43 jmc Exp $"; +static char rcsid[] = "$OpenBSD: auth.c,v 1.27 2003/04/04 20:25:07 deraadt Exp $"; #endif #endif @@ -560,9 +560,9 @@ auth_check_options() /* Default our_name to hostname, and user to our_name */ if (our_name[0] == 0 || usehostname) - strcpy(our_name, hostname); + strlcpy(our_name, hostname, MAXHOSTNAMELEN); if (user[0] == 0) - strcpy(user, our_name); + strlcpy(user, our_name, MAXNAMELEN); /* If authentication is required, ask peer for CHAP or PAP. */ if (auth_required && !wo->neg_chap && !wo->neg_upap) { @@ -1424,7 +1424,7 @@ scan_authfile(f, client, server, ipaddr, secret, addrs, filename) * Special syntax: @filename means read secret from file. */ if (word[0] == '@') { - strcpy(atfile, word+1); + strlcpy(atfile, word+1, sizeof atfile); if ((sf = fopen(atfile, "r")) == NULL) { syslog(LOG_WARNING, "can't open indirect secret file %s", atfile); @@ -1440,7 +1440,7 @@ scan_authfile(f, client, server, ipaddr, secret, addrs, filename) fclose(sf); } if (secret != NULL) - strcpy(lsecret, word); + strlcpy(lsecret, word, sizeof lsecret); /* * Now read address authorization info and make a wordlist. @@ -1478,7 +1478,7 @@ scan_authfile(f, client, server, ipaddr, secret, addrs, filename) free_wordlist(addr_list); addr_list = alist; if (secret != NULL) - strcpy(secret, lsecret); + strlcpy(secret, lsecret, MAXWORDLEN); if (!newline) break; @@ -1525,10 +1525,10 @@ auth_script(script) if ((pw = getpwuid(getuid())) != NULL && pw->pw_name != NULL) user_name = pw->pw_name; else { - sprintf(struid, "%u", getuid()); + snprintf(struid, sizeof struid, "%u", getuid()); user_name = struid; } - sprintf(strspeed, "%d", baud_rate); + snprintf(strspeed, sizeof strspeed, "%d", baud_rate); argv[0] = script; argv[1] = ifname; diff --git a/usr.sbin/pppd/ccp.c b/usr.sbin/pppd/ccp.c index 4dbf91a8603..05526283776 100644 --- a/usr.sbin/pppd/ccp.c +++ b/usr.sbin/pppd/ccp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ccp.c,v 1.11 2002/09/13 00:12:10 deraadt Exp $ */ +/* $OpenBSD: ccp.c,v 1.12 2003/04/04 20:25:07 deraadt Exp $ */ /* * ccp.c - PPP Compression Control Protocol. @@ -39,7 +39,7 @@ #if 0 static char rcsid[] = "Id: ccp.c,v 1.22 1998/03/25 01:25:02 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: ccp.c,v 1.11 2002/09/13 00:12:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ccp.c,v 1.12 2003/04/04 20:25:07 deraadt Exp $"; #endif #endif @@ -885,27 +885,28 @@ method_name(opt, opt2) case CI_DEFLATE: case CI_DEFLATE_DRAFT: if (opt2 != NULL && opt2->deflate_size != opt->deflate_size) - sprintf(result, "Deflate%s (%d/%d)", + snprintf(result, sizeof result, "Deflate%s (%d/%d)", (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""), opt->deflate_size, opt2->deflate_size); else - sprintf(result, "Deflate%s (%d)", + snprintf(result, sizeof result, "Deflate%s (%d)", (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""), opt->deflate_size); break; case CI_BSD_COMPRESS: if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits) - sprintf(result, "BSD-Compress (%d/%d)", opt->bsd_bits, + snprintf(result, sizeof result, + "BSD-Compress (%d/%d)", opt->bsd_bits, opt2->bsd_bits); else - sprintf(result, "BSD-Compress (%d)", opt->bsd_bits); + snprintf(result, sizeof result, "BSD-Compress (%d)", opt->bsd_bits); break; case CI_PREDICTOR_1: return "Predictor 1"; case CI_PREDICTOR_2: return "Predictor 2"; default: - sprintf(result, "Method %d", opt->method); + snprintf(result, sizeof result, "Method %d", opt->method); } return result; } @@ -928,7 +929,7 @@ ccp_up(f) syslog(LOG_NOTICE, "%s compression enabled", method_name(go, ho)); } else { - strcpy(method1, method_name(go, NULL)); + strncpy(method1, method_name(go, NULL), sizeof method1); syslog(LOG_NOTICE, "%s / %s compression enabled", method1, method_name(ho, NULL)); } diff --git a/usr.sbin/pppd/chap.c b/usr.sbin/pppd/chap.c index 43e91198b6b..2eddac898bd 100644 --- a/usr.sbin/pppd/chap.c +++ b/usr.sbin/pppd/chap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chap.c,v 1.11 2002/09/13 00:12:10 deraadt Exp $ */ +/* $OpenBSD: chap.c,v 1.12 2003/04/04 20:25:07 deraadt Exp $ */ /* * chap.c - Challenge Handshake Authentication Protocol. @@ -55,7 +55,7 @@ #if 0 static char rcsid[] = "Id: chap.c,v 1.15 1997/11/27 06:07:48 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: chap.c,v 1.11 2002/09/13 00:12:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: chap.c,v 1.12 2003/04/04 20:25:07 deraadt Exp $"; #endif #endif @@ -738,9 +738,9 @@ ChapSendStatus(cstate, code) char msg[256]; if (code == CHAP_SUCCESS) - sprintf(msg, "Welcome to %s.", hostname); + snprintf(msg, sizeof msg, "Welcome to %s.", hostname); else - sprintf(msg, "I don't like you. Go 'way."); + snprintf(msg, sizeof msg, "I don't like you. Go 'way."); msglen = strlen(msg); outlen = CHAP_HEADERLEN + msglen; diff --git a/usr.sbin/pppd/ipcp.c b/usr.sbin/pppd/ipcp.c index 93282afddfc..578cb771827 100644 --- a/usr.sbin/pppd/ipcp.c +++ b/usr.sbin/pppd/ipcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipcp.c,v 1.9 2002/07/01 19:31:37 deraadt Exp $ */ +/* $OpenBSD: ipcp.c,v 1.10 2003/04/04 20:25:07 deraadt Exp $ */ /* * ipcp.c - PPP IP Control Protocol. @@ -46,7 +46,7 @@ #if 0 static char rcsid[] = "Id: ipcp.c,v 1.34 1998/04/28 23:38:09 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: ipcp.c,v 1.9 2002/07/01 19:31:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ipcp.c,v 1.10 2003/04/04 20:25:07 deraadt Exp $"; #endif #endif @@ -174,7 +174,7 @@ u_int32_t ipaddr; ipaddr = ntohl(ipaddr); - sprintf(b, "%d.%d.%d.%d", + snprintf(b, sizeof b, "%d.%d.%d.%d", (u_char)(ipaddr >> 24), (u_char)(ipaddr >> 16), (u_char)(ipaddr >> 8), @@ -1368,9 +1368,11 @@ ipcp_script(f, script) char strspeed[32], strlocal[32], strremote[32]; char *argv[8]; - sprintf(strspeed, "%d", baud_rate); - strcpy(strlocal, ip_ntoa(ipcp_gotoptions[f->unit].ouraddr)); - strcpy(strremote, ip_ntoa(ipcp_hisoptions[f->unit].hisaddr)); + snprintf(strspeed, sizeof strspeed, "%d", baud_rate); + strlcpy(strlocal, ip_ntoa(ipcp_gotoptions[f->unit].ouraddr), + sizeof strlocal); + strlcpy(strremote, ip_ntoa(ipcp_hisoptions[f->unit].hisaddr), + sizeof strremote); argv[0] = script; argv[1] = ifname; diff --git a/usr.sbin/pppd/ipxcp.c b/usr.sbin/pppd/ipxcp.c index aa057618dfd..dad33181be8 100644 --- a/usr.sbin/pppd/ipxcp.c +++ b/usr.sbin/pppd/ipxcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipxcp.c,v 1.10 2002/07/01 19:31:37 deraadt Exp $ */ +/* $OpenBSD: ipxcp.c,v 1.11 2003/04/04 20:25:07 deraadt Exp $ */ /* * ipxcp.c - PPP IPX Control Protocol. @@ -47,7 +47,7 @@ #if 0 static char rcsid[] = "Id: ipxcp.c,v 1.6 1998/03/25 03:08:16 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: ipxcp.c,v 1.10 2002/07/01 19:31:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ipxcp.c,v 1.11 2003/04/04 20:25:07 deraadt Exp $"; #endif #endif @@ -194,7 +194,8 @@ ipx_ntoa(ipxaddr) u_int32_t ipxaddr; { static char b[64]; - sprintf(b, "%x", ipxaddr); + + snprintf(b, sizeof b, "%x", ipxaddr); return b; } @@ -1239,42 +1240,38 @@ ipxcp_script(f, script) char strnetwork[32], strpid[32]; char *argv[14], strproto_lcl[32], strproto_rmt[32]; - sprintf (strpid, "%ld", (long)getpid()); - sprintf (strspeed, "%d", baud_rate); + snprintf(strpid, sizeof strpid, "%ld", (long)getpid()); + snprintf(strspeed, sizeof strspeed, "%d", baud_rate); strproto_lcl[0] = '\0'; if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) { if (go->router & BIT(RIP_SAP)) - strcpy (strproto_lcl, "RIP "); + strlcpy (strproto_lcl, "RIP ", sizeof strproto_lcl); if (go->router & BIT(NLSP)) - strcat (strproto_lcl, "NLSP "); + strlcat (strproto_lcl, "NLSP ", sizeof strproto_lcl); } if (strproto_lcl[0] == '\0') - strcpy (strproto_lcl, "NONE "); - - strproto_lcl[strlen (strproto_lcl)-1] = '\0'; + strlcpy (strproto_lcl, "NONE ", sizeof strproto_lcl); strproto_rmt[0] = '\0'; if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) { if (ho->router & BIT(RIP_SAP)) - strcpy (strproto_rmt, "RIP "); + strlcpy (strproto_rmt, "RIP ", sizeof strproto_rmt); if (ho->router & BIT(NLSP)) - strcat (strproto_rmt, "NLSP "); + strlcat (strproto_rmt, "NLSP ", sizeof strproto_rmt); } if (strproto_rmt[0] == '\0') - strcpy (strproto_rmt, "NONE "); - - strproto_rmt[strlen (strproto_rmt)-1] = '\0'; + strlcpy (strproto_rmt, "NONE ", sizeof strproto_rmt); - strcpy (strnetwork, ipx_ntoa (go->network)); + strlcpy (strnetwork, ipx_ntoa (go->network), sizeof strnetwork); - sprintf (strlocal, + snprintf (strlocal, sizeof strlocal, "%02X%02X%02X%02X%02X%02X", NODE(go->our_node)); - sprintf (strremote, + snprintf (strremote, sizeof strremote, "%02X%02X%02X%02X%02X%02X", NODE(ho->his_node)); diff --git a/usr.sbin/pppd/main.c b/usr.sbin/pppd/main.c index 22ce837206d..4c65b55580e 100644 --- a/usr.sbin/pppd/main.c +++ b/usr.sbin/pppd/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.39 2002/07/29 22:02:38 millert Exp $ */ +/* $OpenBSD: main.c,v 1.40 2003/04/04 20:25:07 deraadt Exp $ */ /* * main.c - Point-to-Point Protocol main module @@ -46,7 +46,7 @@ #if 0 static char rcsid[] = "Id: main.c,v 1.49 1998/05/05 05:24:17 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.39 2002/07/29 22:02:38 millert Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.40 2003/04/04 20:25:07 deraadt Exp $"; #endif #endif @@ -208,8 +208,8 @@ main(argc, argv) phase = PHASE_INITIALIZE; p = ttyname(0); if (p) - strcpy(devnam, p); - strcpy(default_devnam, devnam); + strlcpy(devnam, p, MAXPATHLEN); + strlcpy(default_devnam, devnam, sizeof default_devnam); script_env = NULL; @@ -228,7 +228,7 @@ main(argc, argv) uid = getuid(); privileged = uid == 0; - sprintf(numbuf, "%u", uid); + snprintf(numbuf, sizeof numbuf, "%u", uid); script_setenv("UID", numbuf); /* @@ -277,7 +277,7 @@ main(argc, argv) } script_setenv("DEVICE", devnam); - sprintf(numbuf, "%d", baud_rate); + snprintf(numbuf, sizeof numbuf, "%d", baud_rate); script_setenv("SPEED", numbuf); /* @@ -402,7 +402,7 @@ main(argc, argv) open_ppp_loopback(); syslog(LOG_INFO, "Using interface ppp%d", ifunit); - (void) sprintf(ifname, "ppp%d", ifunit); + (void) snprintf(ifname, sizeof ifname, "ppp%d", ifunit); script_setenv("IFNAME", ifname); create_pidfile(); /* write pid to file */ @@ -541,7 +541,7 @@ main(argc, argv) if (!demand) { syslog(LOG_INFO, "Using interface ppp%d", ifunit); - (void) sprintf(ifname, "ppp%d", ifunit); + (void) snprintf(ifname, sizeof ifname, "ppp%d", ifunit); script_setenv("IFNAME", ifname); create_pidfile(); /* write pid to file */ @@ -661,7 +661,8 @@ create_pidfile() { FILE *pidfile; - (void) sprintf(pidfilename, "%s%s.pid", _PATH_VARRUN, ifname); + (void) snprintf(pidfilename, sizeof pidfilename, + "%s%s.pid", _PATH_VARRUN, ifname); if ((pidfile = fopen(pidfilename, "w")) != NULL) { fprintf(pidfile, "%ld\n", (long)pid); (void) fclose(pidfile); @@ -1277,7 +1278,7 @@ log_packet(p, len, prefix, level) char *prefix; int level; { - strcpy(line, prefix); + strlcpy(line, prefix, sizeof line); linep = line + strlen(line); format_packet(p, len, pr_log, NULL); if (linep != line) @@ -1645,12 +1646,8 @@ script_setenv(var, value) int i; char *p, *newstring; - newstring = (char *) malloc(vl + strlen(value) + 2); - if (newstring == 0) + if (asprintf(&newstring, "%s=%s", var, value) == -1) novm("script_setenv"); - strcpy(newstring, var); - newstring[vl] = '='; - strcpy(newstring+vl+1, value); /* check if this variable is already set */ if (script_env != 0) { diff --git a/usr.sbin/pppd/options.c b/usr.sbin/pppd/options.c index 7928f388b37..6a110ad958e 100644 --- a/usr.sbin/pppd/options.c +++ b/usr.sbin/pppd/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.18 2002/12/23 21:07:43 mickey Exp $ */ +/* $OpenBSD: options.c,v 1.19 2003/04/04 20:25:07 deraadt Exp $ */ /* * options.c - handles option processing for PPP. @@ -46,7 +46,7 @@ #if 0 static char rcsid[] = "Id: options.c,v 1.42 1998/03/26 04:46:06 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: options.c,v 1.18 2002/12/23 21:07:43 mickey Exp $"; +static char rcsid[] = "$OpenBSD: options.c,v 1.19 2003/04/04 20:25:07 deraadt Exp $"; #endif #endif @@ -700,12 +700,8 @@ options_from_user() if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0) return 1; file = _PATH_USEROPT; - path = malloc(strlen(user) + strlen(file) + 2); - if (path == NULL) + if (asprintf(&path, "%s/%s", user, file) == -1) novm("init file name"); - strcpy(path, user); - strcat(path, "/"); - strcat(path, file); ret = options_from_file(path, 0, 1, privileged); free(path); return ret; @@ -726,14 +722,8 @@ options_for_tty() dev += 5; if (strcmp(dev, "tty") == 0) return 1; /* don't look for /etc/ppp/options.tty */ - path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1); - if (path == NULL) + if (asprintf(&path, "%s%s", _PATH_TTYOPT, dev) == -1) novm("tty init file name"); - strcpy(path, _PATH_TTYOPT); - /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */ - for (p = path + strlen(path); *dev != 0; ++dev) - *p++ = (*dev == '/'? '.': *dev); - *p = 0; ret = options_from_file(path, 0, 0, 1); free(path); return ret; @@ -1121,8 +1111,8 @@ callfile(argv) l = strlen(arg) + strlen(_PATH_PEERFILES) + 1; if ((fname = (char *) malloc(l)) == NULL) novm("call file name"); - strcpy(fname, _PATH_PEERFILES); - strcat(fname, arg); + strlcpy(fname, _PATH_PEERFILES, l); + strlcat(fname, arg, l); ok = options_from_file(fname, 1, 1, 1); @@ -1687,9 +1677,8 @@ setdevname(cp, quiet) return 0; if (strncmp("/dev/", cp, 5) != 0) { - strcpy(dev, "/dev/"); - strncat(dev, cp, MAXPATHLEN - 5); - dev[MAXPATHLEN-1] = 0; + strlcpy(dev, "/dev/", sizeof dev); + strlcat(dev, cp, sizeof dev); cp = dev; } diff --git a/usr.sbin/pppd/sys-bsd.c b/usr.sbin/pppd/sys-bsd.c index bbed485884d..b527d115b2e 100644 --- a/usr.sbin/pppd/sys-bsd.c +++ b/usr.sbin/pppd/sys-bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys-bsd.c,v 1.19 2002/09/13 00:12:10 deraadt Exp $ */ +/* $OpenBSD: sys-bsd.c,v 1.20 2003/04/04 20:25:07 deraadt Exp $ */ /* * sys-bsd.c - System-dependent procedures for setting up @@ -78,7 +78,7 @@ #if 0 static char rcsid[] = "Id: sys-bsd.c,v 1.31 1998/04/02 12:04:19 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: sys-bsd.c,v 1.19 2002/09/13 00:12:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: sys-bsd.c,v 1.20 2003/04/04 20:25:07 deraadt Exp $"; #endif #endif @@ -1593,10 +1593,8 @@ lock(dev) if ((p = strrchr(dev, '/')) != NULL) dev = p + 1; - lock_file = malloc(strlen(LOCK_PREFIX) + strlen(dev) + 1); - if (lock_file == NULL) + if (asprintf(&lock_file, "%s%s", LOCK_PREFIX, dev) == -1) novm("lock file name"); - strcat(strcpy(lock_file, LOCK_PREFIX), dev); while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) { if (errno == EEXIST @@ -1631,7 +1629,7 @@ lock(dev) return -1; } - sprintf(hdb_lock_buffer, "%10ld\n", (long)getpid()); + snprintf(hdb_lock_buffer, sizeof hdb_lock_buffer, "%10ld\n", (long)getpid()); write(fd, hdb_lock_buffer, 11); close(fd); |