]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
auth: Don't overflow hostName array
authorSimon Wilkinson <sxw@your-file-system.com>
Sat, 2 Mar 2013 09:59:20 +0000 (09:59 +0000)
committerStephan Wiesand <stephan.wiesand@desy.de>
Tue, 3 Jun 2014 16:39:01 +0000 (12:39 -0400)
afsconf_cell's hostName structure is a fixed length. Don't overflow
it by writing whatever comes back from gethostbyaddr into it. Use
strlcpy to catch an overflow, and if one occurs, just use
"UNKNOWNHOST", rather than a truncated host name.

Caught by coverity (#985906)

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

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

index 4e43f7fb7077cea0ba68859c2206a1e066e38cd6..185bbc473b91169b11b44eeacdeb6084455f868b 100644 (file)
@@ -71,7 +71,12 @@ VerifyEntries(struct afsconf_cell *aci)
            if (!th) {
                strcpy(aci->hostName[i], "UNKNOWNHOST");
            } else {
-               strcpy(aci->hostName[i], th->h_name);
+               if (strlcpy(aci->hostName[i],
+                           th->h_name,
+                           sizeof(aci->hostName[i]))
+                       >= sizeof(aci->hostName[i])) {
+                  strcpy(aci->hostName[i], "UNKNOWNHOST");
+               }
            }
        }
     }