diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-06 00:45:13 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-06 00:45:13 +0000 |
commit | 057d758e78c071130b4f93385190d9c5aea0b8b7 (patch) | |
tree | 0c871f4299ff9b0b1ec8f4fb08c1f18b98fd605e | |
parent | 5b13269d7ba4c60cfa150b2f5d5f343b8fa5aa38 (diff) |
string handling; ok millert
-rw-r--r-- | lib/libc/time/zic.c | 35 | ||||
-rw-r--r-- | libexec/getNAME/getNAME.c | 8 | ||||
-rw-r--r-- | sbin/disklabel/disklabel.c | 21 | ||||
-rw-r--r-- | sbin/routed/rtquery/rtquery.c | 14 |
4 files changed, 46 insertions, 32 deletions
diff --git a/lib/libc/time/zic.c b/lib/libc/time/zic.c index 1811a135857..4a8411f4d2d 100644 --- a/lib/libc/time/zic.c +++ b/lib/libc/time/zic.c @@ -5,7 +5,7 @@ #if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID) static char elsieid[] = "@(#)zic.c 7.107"; -static char rcsid[] = "$OpenBSD: zic.c,v 1.19 2003/04/05 04:16:09 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: zic.c,v 1.20 2003/04/06 00:44:36 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include "private.h" @@ -961,22 +961,25 @@ const int nfields; { register int i; static char * buf; + size_t len; if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS) { error(_("wrong number of fields on Zone line")); return FALSE; } if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL) { - buf = erealloc(buf, (int) (132 + strlen(TZDEFAULT))); - (void) sprintf(buf, + len = 132 + strlen(TZDEFAULT); + buf = erealloc(buf, len); + (void) snprintf(buf, len, _("\"Zone %s\" line and -l option are mutually exclusive"), TZDEFAULT); error(buf); return FALSE; } if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL) { - buf = erealloc(buf, (int) (132 + strlen(TZDEFRULES))); - (void) sprintf(buf, + len = 132 + strlen(TZDEFRULES); + buf = erealloc(buf, len); + (void) snprintf(buf, len, _("\"Zone %s\" line and -p option are mutually exclusive"), TZDEFRULES); error(buf); @@ -985,10 +988,10 @@ _("\"Zone %s\" line and -p option are mutually exclusive"), for (i = 0; i < nzones; ++i) if (zones[i].z_name != NULL && strcmp(zones[i].z_name, fields[ZF_NAME]) == 0) { - buf = erealloc(buf, (int) (132 + - strlen(fields[ZF_NAME]) + - strlen(zones[i].z_filename))); - (void) sprintf(buf, + len = 132 + strlen(fields[ZF_NAME]) + + strlen(zones[i].z_filename); + buf = erealloc(buf, len); + (void) snprintf(buf, len, _("duplicate zone name %s (file \"%s\", line %d)"), fields[ZF_NAME], zones[i].z_filename, @@ -1417,6 +1420,7 @@ const char * const name; static struct tzhead tzh; time_t ats[TZ_MAX_TIMES]; unsigned char types[TZ_MAX_TIMES]; + size_t len; /* ** Sort. @@ -1461,9 +1465,10 @@ const char * const name; ats[i] = attypes[i].at; types[i] = attypes[i].type; } - fullname = erealloc(fullname, - (int) (strlen(directory) + 1 + strlen(name) + 1)); - (void) sprintf(fullname, "%s/%s", directory, name); + len = strlen(directory) + 1 + strlen(name) + 1; + fullname = erealloc(fullname, len); + + (void) snprintf(fullname, len, "%s/%s", directory, name); /* ** Remove old file, if any, to snap links. */ @@ -1905,11 +1910,13 @@ const char * const type; { static char * buf; int result; + size_t len; if (type == NULL || *type == '\0') return TRUE; - buf = erealloc(buf, (int) (132 + strlen(yitcommand) + strlen(type))); - (void) sprintf(buf, "%s %d %s", yitcommand, year, type); + len = 132 + strlen(yitcommand) + strlen(type); + buf = erealloc(buf, len); + (void) snprintf(buf, len, "%s %d %s", yitcommand, year, type); result = system(buf); if (WIFEXITED(result)) switch (WEXITSTATUS(result)) { case 0: diff --git a/libexec/getNAME/getNAME.c b/libexec/getNAME/getNAME.c index e31293708e2..059199f90b0 100644 --- a/libexec/getNAME/getNAME.c +++ b/libexec/getNAME/getNAME.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getNAME.c,v 1.10 2002/07/03 23:39:03 deraadt Exp $ */ +/* $OpenBSD: getNAME.c,v 1.11 2003/04/06 00:45:12 deraadt Exp $ */ /* $NetBSD: getNAME.c,v 1.7.2.1 1997/11/10 19:54:46 thorpej Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)getNAME.c 8.1 (Berkeley) 6/30/93"; #else -static char rcsid[] = "$OpenBSD: getNAME.c,v 1.10 2002/07/03 23:39:03 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: getNAME.c,v 1.11 2003/04/06 00:45:12 deraadt Exp $"; #endif #endif /* not lint */ @@ -217,7 +217,7 @@ newman: trimln(headbuf); for (loc = strchr(headbuf, ' '); loc; loc = strchr(loc, ' ')) if (loc[1] == ',') - strcpy(loc, &loc[1]); + memmove(loc, &loc[1], strlen(&loc[1])+1); else loc++; if (headbuf[0] != '.') { @@ -228,7 +228,7 @@ newman: * Get rid of quotes in macros. */ for (loc = strchr(&headbuf[4], '"'); loc; ) { - strcpy(loc, &loc[1]); + memmove(loc, &loc[1], strlen(&loc[1])+1); loc = strchr(loc, '"'); } /* diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 0b48cb6d26e..5def7f4623a 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.78 2003/02/13 00:10:39 tedu Exp $ */ +/* $OpenBSD: disklabel.c,v 1.79 2003/04/06 00:45:12 deraadt Exp $ */ /* * Copyright (c) 1987, 1993 @@ -43,7 +43,7 @@ static const char copyright[] = #endif /* not lint */ #ifndef lint -static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.78 2003/02/13 00:10:39 tedu Exp $"; +static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.79 2003/04/06 00:45:12 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -818,24 +818,25 @@ makebootarea(boot, dp, f) *np++ = '\0'; if (!xxboot) { - (void)sprintf(np, "%s%sboot", - _PATH_BOOTDIR, dkbasename); + (void)snprintf(np, namebuf + sizeof namebuf - np, + "%s%sboot", _PATH_BOOTDIR, dkbasename); if (access(np, F_OK) < 0 && dkbasename[0] == 'r') dkbasename++; xxboot = np; - (void)sprintf(xxboot, "%s%sboot", - _PATH_BOOTDIR, dkbasename); + (void)snprintf(xxboot, + namebuf + sizeof namebuf - np, + "%s%sboot", _PATH_BOOTDIR, dkbasename); np += strlen(xxboot) + 1; } #if NUMBOOT > 1 if (!bootxx) { - (void)sprintf(np, "%sboot%s", - _PATH_BOOTDIR, dkbasename); + (void)snprintf(np, namebuf + sizeof namebuf - np, + "%sboot%s", _PATH_BOOTDIR, dkbasename); if (access(np, F_OK) < 0 && dkbasename[0] == 'r') dkbasename++; bootxx = np; - (void)sprintf(bootxx, "%sboot%s", - _PATH_BOOTDIR, dkbasename); + (void)snprintf(bootxx, namebuf + sizeof namebuf - bootxx, + "%sboot%s", _PATH_BOOTDIR, dkbasename); np += strlen(bootxx) + 1; } #endif diff --git a/sbin/routed/rtquery/rtquery.c b/sbin/routed/rtquery/rtquery.c index c4230a090c6..5eb187701c2 100644 --- a/sbin/routed/rtquery/rtquery.c +++ b/sbin/routed/rtquery/rtquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtquery.c,v 1.12 2003/04/04 00:46:24 deraadt Exp $ */ +/* $OpenBSD: rtquery.c,v 1.13 2003/04/06 00:45:12 deraadt Exp $ */ /*- * Copyright (c) 1982, 1986, 1993 @@ -492,16 +492,22 @@ rip_input(struct sockaddr_in *from, if (mask != 0) { sp = &net_buf[strlen(net_buf)]; if (IMSG.rip_vers == RIPv1) { - sprintf(sp," mask=%#x ? ",mask); + snprintf(sp, + net_buf + sizeof net_buf - sp, + " mask=%#x ? ",mask); mask = 0; } else if (mask + dmask == 0) { for (i = 0; (i != 32 && ((1<<i)&mask) == 0); i++) continue; - sprintf(sp, "/%d",32-i); + snprintf(sp, + net_buf + sizeof net_buf - sp, + "/%d",32-i); } else - sprintf(sp," (mask %#x)", mask); + snprintf(sp, + net_buf + sizeof net_buf - sp, + " (mask %#x)", mask); } if (!nflag) { |