diff options
author | Moritz Jodeit <moritz@cvs.openbsd.org> | 2005-05-02 17:51:38 +0000 |
---|---|---|
committer | Moritz Jodeit <moritz@cvs.openbsd.org> | 2005-05-02 17:51:38 +0000 |
commit | f2488db2968553088f755441bf270e7347e18d7e (patch) | |
tree | fe5d804b573daca9e1811efebdcf4ddf71c1a5df | |
parent | f05ba942ed8ca9328c30e6b262e6cf2ed8fc31a4 (diff) |
fix snprintf misuse. ok bob@ hin@
-rw-r--r-- | usr.sbin/afs/src/appl/fs/fs_copyacl.c | 6 | ||||
-rw-r--r-- | usr.sbin/afs/src/arlad/dynroot.c | 2 | ||||
-rw-r--r-- | usr.sbin/afs/src/arlad/fcache.c | 6 | ||||
-rw-r--r-- | usr.sbin/afs/src/milko/lib/vld/common.c | 10 | ||||
-rw-r--r-- | usr.sbin/afs/src/milko/lib/voldb/vol.c | 4 | ||||
-rw-r--r-- | usr.sbin/afs/src/util/log.c | 8 |
6 files changed, 20 insertions, 16 deletions
diff --git a/usr.sbin/afs/src/appl/fs/fs_copyacl.c b/usr.sbin/afs/src/appl/fs/fs_copyacl.c index 2a37040a1a9..236a924c756 100644 --- a/usr.sbin/afs/src/appl/fs/fs_copyacl.c +++ b/usr.sbin/afs/src/appl/fs/fs_copyacl.c @@ -51,7 +51,7 @@ afs_copyacl(char *fromdir, char *todir) acl->NumPositiveEntries, acl->NumNegativeEntries); len = l; - if (len >= sizeof(acltext)) { + if (len == -1 || len >= sizeof(acltext)) { fserr(PROGNAME, ERANGE, todir); return; } @@ -60,7 +60,7 @@ afs_copyacl(char *fromdir, char *todir) l = snprintf(acltext + len, sizeof(acltext) - len, "%s %d\n", position->name, position->RightsMask); len += l; - if (len >= sizeof(acltext)) { + if (l == -1 || len >= sizeof(acltext)) { fserr(PROGNAME, ERANGE, todir); return; } @@ -71,7 +71,7 @@ afs_copyacl(char *fromdir, char *todir) l = snprintf(acltext + len, sizeof(acltext) - len, "%s %d\n", position->name, position->RightsMask); len += l; - if (len >= sizeof(acltext)) { + if (l == -1 || len >= sizeof(acltext)) { fserr(PROGNAME, ERANGE, todir); return; } diff --git a/usr.sbin/afs/src/arlad/dynroot.c b/usr.sbin/afs/src/arlad/dynroot.c index 49fec78e70b..2a67a51278e 100644 --- a/usr.sbin/afs/src/arlad/dynroot.c +++ b/usr.sbin/afs/src/arlad/dynroot.c @@ -188,7 +188,7 @@ dynroot_create_symlink (fbuf *fbuf, int32_t vnode) len = snprintf (name, sizeof(name), "%c%s:root.cell.", rw ? '%' : '#', cell->name); - assert (len > 0 && len <= sizeof (name)); + assert (len > 0 && len < sizeof (name)); ret = fbuf_truncate (fbuf, len); if (ret) diff --git a/usr.sbin/afs/src/arlad/fcache.c b/usr.sbin/afs/src/arlad/fcache.c index b559ee1b2dd..c089d5f0b89 100644 --- a/usr.sbin/afs/src/arlad/fcache.c +++ b/usr.sbin/afs/src/arlad/fcache.c @@ -508,10 +508,10 @@ fcache_fhget (char *filename, fcache_cache_handle *handle) GetCurrentDirectory(1024, buf); - /* XXX CACHEHANDLESIZE */ - ret = snprintf ((char *)handle, 80, "%s\\%02X\\%02X", buf, a, b); + ret = snprintf ((char *)handle, CACHEHANDLESIZE, + "%s\\%02X\\%02X", buf, a, b); - if (ret > 0) + if (ret > 0 && ret < CACHEHANDLESIZE) handle->valid = 1; return ret; diff --git a/usr.sbin/afs/src/milko/lib/vld/common.c b/usr.sbin/afs/src/milko/lib/vld/common.c index 5ded95a2851..58fadadc548 100644 --- a/usr.sbin/afs/src/milko/lib/vld/common.c +++ b/usr.sbin/afs/src/milko/lib/vld/common.c @@ -156,7 +156,7 @@ local_create_name (struct dp_part *dp, int32_t num, char *name, size_t sz) (unsigned int) (num >> 8) & 0xff, (unsigned int) num & 0xff); - if (i >= sz) + if (i == -1 || i >= sz) return(-1); return 0; } @@ -172,7 +172,7 @@ local_create_file (struct dp_part *dp, onode_opaque *o, i = snprintf(nodename, sizeof(nodename), "%s/inodeXXXXXXXXXX", DP_NAME(dp)); - if (i > sizeof(nodename)) + if (i == -1 || i >= sizeof(nodename)) return(ENOMEM); fd = mkstemp(nodename); @@ -198,7 +198,7 @@ local_create_file (struct dp_part *dp, onode_opaque *o, i = snprintf(name, sizeof(name), "%s/%02x", DP_NAME(dp), (unsigned int) (sb.st_ino >> 24) & 0xff); - if (i > sizeof(name)) { + if (i == -1 || i >= sizeof(name)) { ret = ENOMEM goto bad; } @@ -206,7 +206,7 @@ local_create_file (struct dp_part *dp, onode_opaque *o, i = snprintf(name, sizeof(name), "%s/%02x/%02x", DP_NAME(dp), (unsigned int) (sb.st_ino >> 24) & 0xff, (unsigned int) (sb.st_ino >> 16) & 0xff); - if (i > sizeof(name)) { + if (i == -1 || i >= sizeof(name)) { ret = ENOMEM goto bad; } @@ -216,7 +216,7 @@ local_create_file (struct dp_part *dp, onode_opaque *o, (unsigned int) (sb.st_ino >> 24) & 0xff, (unsigned int) (sb.st_ino >> 16) & 0xff, (unsigned int) (sb.st_ino >> 8) & 0xff); - if (i > sizeof(name)) { + if (i == -1 || i >= sizeof(name)) { ret = ENOMEM goto bad; } diff --git a/usr.sbin/afs/src/milko/lib/voldb/vol.c b/usr.sbin/afs/src/milko/lib/voldb/vol.c index acb51ad96fc..70ef4f2a283 100644 --- a/usr.sbin/afs/src/milko/lib/voldb/vol.c +++ b/usr.sbin/afs/src/milko/lib/voldb/vol.c @@ -50,7 +50,7 @@ vol_getname (uint32_t num, char *str, size_t sz) { int i; i = snprintf (str, sz, "vol%08u", num); - assert (i > 0); + assert (i > 0 && i < sz); return 0; } @@ -83,7 +83,7 @@ vol_getfullname (uint32_t part, uint32_t num, char *str, size_t sz) else return EINVAL; /* XXX */ - assert (ret > 0); + assert (ret > 0 && ret < siz); return 0; } diff --git a/usr.sbin/afs/src/util/log.c b/usr.sbin/afs/src/util/log.c index 6e8240fc56f..aa369fd7f4c 100644 --- a/usr.sbin/afs/src/util/log.c +++ b/usr.sbin/afs/src/util/log.c @@ -735,7 +735,9 @@ _print_unit (Log_unit *unit, char *buf, size_t sz) if (sz <= 0) return(0); ret = snprintf (buf, sz, "%s:", unit->name); - if (ret == -1 || ret >= sz) + if (ret == -1) + ret = 0; + if (ret >= sz) ret = sz - 1; UPDATESZ(buf,sz,ret); ret = unparse_flags (log_get_mask (unit), unit->unit, buf, sz); @@ -758,7 +760,9 @@ log_mask2str (Log_method *method, Log_unit *unit, char *buf, size_t sz) if (log_get_mask (method->units[i])) { if (printed && sz > 0) { ret = snprintf (buf, sz, ";"); - if (ret == -1 || ret >= sz) + if (ret == -1) + ret = 0; + if (ret >= sz) ret = sz - 1; UPDATESZ(buf,sz,ret); } |