use bounded string op as much as possible
This commit is contained in:
parent
8747acfc51
commit
232b5bf80e
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mount_fs.c,v 1.7 2003/03/09 01:38:49 christos Exp $ */
|
||||
/* $NetBSD: mount_fs.c,v 1.8 2003/07/14 17:25:41 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997-2003 Erez Zadok
|
||||
|
@ -273,10 +273,10 @@ again:
|
|||
/* add the extra dev= field to the mount table */
|
||||
if (lstat(mnt->mnt_dir, &stb) == 0) {
|
||||
if (sizeof(stb.st_dev) == 2) /* e.g. SunOS 4.1 */
|
||||
sprintf(optsbuf, "%s=%04lx",
|
||||
snprintf(optsbuf, sizeof(optsbuf), "%s=%04lx",
|
||||
MNTTAB_OPT_DEV, (u_long) stb.st_dev & 0xffff);
|
||||
else /* e.g. System Vr4 */
|
||||
sprintf(optsbuf, "%s=%08lx",
|
||||
snprintf(optsbuf, sizeof(optsbuf), "%s=%08lx",
|
||||
MNTTAB_OPT_DEV, (u_long) stb.st_dev);
|
||||
append_opts(zopts, optsbuf);
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ again:
|
|||
*/
|
||||
if (nfs_version == NFS_VERSION3 &&
|
||||
hasmntval(mnt, MNTTAB_OPT_VERS) != NFS_VERSION3) {
|
||||
sprintf(optsbuf, "%s=%d", MNTTAB_OPT_VERS, NFS_VERSION3);
|
||||
snprintf(optsbuf, sizeof(optsbuf), "%s=%d", MNTTAB_OPT_VERS, NFS_VERSION3);
|
||||
append_opts(zopts, optsbuf);
|
||||
}
|
||||
# endif /* defined(HAVE_FS_NFS3) && defined(MNTTAB_OPT_VERS) */
|
||||
|
@ -302,7 +302,7 @@ again:
|
|||
* unless already specified by user.
|
||||
*/
|
||||
if (nfs_proto && !amu_hasmntopt(mnt, MNTTAB_OPT_PROTO)) {
|
||||
sprintf(optsbuf, "%s=%s", MNTTAB_OPT_PROTO, nfs_proto);
|
||||
snprintf(optsbuf, sizeof(optsbuf), "%s=%s", MNTTAB_OPT_PROTO, nfs_proto);
|
||||
append_opts(zopts, optsbuf);
|
||||
}
|
||||
# endif /* MNTTAB_OPT_PROTO */
|
||||
|
@ -326,7 +326,7 @@ again:
|
|||
# ifdef HAVE_MNTENT_T_MNT_TIME_STRING
|
||||
{ /* allocate enough space for a long */
|
||||
char *str = (char *) xmalloc(13 * sizeof(char));
|
||||
sprintf(str, "%ld", time((time_t *) NULL));
|
||||
snprintf(str, 13, "%ld", time((time_t *) NULL));
|
||||
mnt->mnt_time = str;
|
||||
}
|
||||
# else /* not HAVE_MNTENT_T_MNT_TIME_STRING */
|
||||
|
@ -844,8 +844,8 @@ get_hex_string(u_int len, const char *fhdata)
|
|||
memset(&arr[0], 0, (64 * sizeof(short int)));
|
||||
memcpy(&arr[0], &fhdata[0], len);
|
||||
for (i=0; i<len/sizeof(short int); i++) {
|
||||
sprintf(str, "%04x", ntohs(arr[i]));
|
||||
strcat(buf, str);
|
||||
snprintf(str, sizeof(str), "%04x", ntohs(arr[i]));
|
||||
strlcat(buf, str, sizeof(buf));
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: wire.c,v 1.6 2003/03/09 01:38:49 christos Exp $ */
|
||||
/* $NetBSD: wire.c,v 1.7 2003/07/14 17:25:42 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997-2003 Erez Zadok
|
||||
|
@ -108,26 +108,26 @@ print_wires(void)
|
|||
return NULL;
|
||||
|
||||
if (!localnets) {
|
||||
sprintf(buf, "No networks.\n");
|
||||
snprintf(buf, buf_size, "No networks.\n");
|
||||
return buf;
|
||||
}
|
||||
/* check if there's more than one network */
|
||||
if (!localnets->ip_next) {
|
||||
sprintf(buf,
|
||||
snprintf(buf, 1024,
|
||||
"Network: wire=\"%s\" (netnumber=%s).\n",
|
||||
localnets->ip_net_name, localnets->ip_net_num);
|
||||
return buf;
|
||||
}
|
||||
buf[0] = '\0'; /* null out buffer before appending */
|
||||
for (i = 1, al = localnets; al; al = al->ip_next, i++) {
|
||||
sprintf(s, "Network %d: wire=\"%s\" (netnumber=%s).\n",
|
||||
snprintf(s, sizeof(s), "Network %d: wire=\"%s\" (netnumber=%s).\n",
|
||||
i, al->ip_net_name, al->ip_net_num);
|
||||
bufcount += strlen(s);
|
||||
if (bufcount > buf_size) {
|
||||
buf_size *= 2;
|
||||
buf = xrealloc(buf, buf_size);
|
||||
}
|
||||
strcat(buf, s);
|
||||
strlcat(buf, s, buf_size);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
@ -212,16 +212,16 @@ getwire_lookup(u_long address, u_long netmask, int ishost)
|
|||
}
|
||||
|
||||
if ((subnet & 0xffffff) == 0) {
|
||||
sprintf(netNumberBuf, "%lu", C(subnet >> 24));
|
||||
snprintf(netNumberBuf, sizeof(netNumberBuf), "%lu", C(subnet >> 24));
|
||||
} else if ((subnet & 0xffff) == 0) {
|
||||
sprintf(netNumberBuf, "%lu.%lu",
|
||||
snprintf(netNumberBuf, sizeof(netNumberBuf), "%lu.%lu",
|
||||
C(subnet >> 24), C(subnet >> 16));
|
||||
} else if ((subnet & 0xff) == 0) {
|
||||
sprintf(netNumberBuf, "%lu.%lu.%lu",
|
||||
snprintf(netNumberBuf, sizeof(netNumberBuf), "%lu.%lu.%lu",
|
||||
C(subnet >> 24), C(subnet >> 16),
|
||||
C(subnet >> 8));
|
||||
} else {
|
||||
sprintf(netNumberBuf, "%lu.%lu.%lu.%lu",
|
||||
snprintf(netNumberBuf, sizeof(netNumberBuf), "%lu.%lu.%lu.%lu",
|
||||
C(subnet >> 24), C(subnet >> 16),
|
||||
C(subnet >> 8), C(subnet));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue