]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
util: Avoid overflow in GetNameByINet
authorSimon Wilkinson <sxw@your-file-system.com>
Sat, 2 Mar 2013 10:27:47 +0000 (10:27 +0000)
committerStephan Wiesand <stephan.wiesand@desy.de>
Tue, 3 Jun 2014 16:51:12 +0000 (12:51 -0400)
We copy the results of gethostbyaddr into a fixed length buffer
without checking whether they fit. Add a length check, and use
strlcpy to do the copy to make sure we can't overflow.

Caught by coverity (#985912, #985872)

Reviewed-on: http://gerrit.openafs.org/9393
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
(cherry picked from commit fcb7974b838c2b37a8b81b88b11905c6ece398f6)

Change-Id: I2d7f781c159999e721504cd6eec408db93bb703c
Reviewed-on: http://gerrit.openafs.org/11056
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
src/util/hostparse.c

index ede75ab9fdfdcac143c949c108f0c24e1906d39e..bbd8296dc8ba60137aeb3cddeab0eb2f39a068b0 100644 (file)
@@ -114,8 +114,8 @@ hostutil_GetNameByINet(afs_uint32 addr)
        return NULL;
 #endif
     th = gethostbyaddr((void *)&addr, sizeof(addr), AF_INET);
-    if (th) {
-       strcpy(tbuffer, th->h_name);
+    if (th && strlen(th->h_name) < sizeof(tbuffer)) {
+       strlcpy(tbuffer, th->h_name, sizeof(tbuffer));
     } else {
        addr = ntohl(addr);
        sprintf(tbuffer, "%d.%d.%d.%d", (int)((addr >> 24) & 0xff),