]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
auth: Don't overflow buffer in CompFindUser
authorSimon Wilkinson <sxw@your-file-system.com>
Sat, 2 Mar 2013 13:01:14 +0000 (13:01 +0000)
committerStephan Wiesand <stephan.wiesand@desy.de>
Tue, 3 Jun 2014 16:57:22 +0000 (12:57 -0400)
The fullname buffer in CompFindUser is theoretically big enough
to take the data usually supplied to it. However, play it safe by
using strlcat and strlcpy to catch buffer overflows.

Caught by coverity (#985771)

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

Change-Id: I900611e13d6254c4410915b0688b18a3b6c4acc3
Reviewed-on: http://gerrit.openafs.org/11063
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/userok.c

index e35da8185aae910cb8e1372e0e438adc9adc5abd..68b6fbf2624db2a37ed8c982b36b78ba7b93a936 100644 (file)
@@ -310,7 +310,9 @@ CompFindUser(struct afsconf_dir *adir, char *name, char *sep, char *inst,
     if (!name || !name[0]) {
        return NULL;
     }
-    strcpy(fullname, name);
+
+    if (strlcpy(fullname, name, sizeof(fullname)) >= sizeof(fullname))
+       return NULL;
 
     /* might have instance */
     if (inst && inst[0]) {
@@ -318,14 +320,20 @@ CompFindUser(struct afsconf_dir *adir, char *name, char *sep, char *inst,
            return NULL;
        }
 
-       strcat(fullname, sep);
-       strcat(fullname, inst);
+       if (strlcat(fullname, sep, sizeof(fullname)) >= sizeof(fullname))
+           return NULL;
+
+       if (strlcat(fullname, inst, sizeof(fullname)) >= sizeof(fullname))
+           return NULL;
     }
 
     /* might have realm */
     if (realm && realm[0]) {
-       strcat(fullname, "@");
-       strcat(fullname, realm);
+       if (strlcat(fullname, "@", sizeof(fullname)) >= sizeof(fullname))
+           return NULL;
+
+       if (strlcat(fullname, realm, sizeof(fullname)) >= sizeof(fullname))
+           return NULL;
     }
 
     if (FindUser(adir, fullname)) {