]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
kauth: Fix overflow when writing ticket file
authorSimon Wilkinson <sxw@your-file-system.com>
Tue, 26 Feb 2013 22:40:04 +0000 (22:40 +0000)
committerStephan Wiesand <stephan.wiesand@desy.de>
Tue, 3 Jun 2014 16:20:26 +0000 (12:20 -0400)
krb_write_ticket_file uses a fixed length buffer to store the name
of the ticket file, but copies into this from an environment variable.

Remove the fixed length buffer, and use a mixture of the variable
itself, and dynamically allocated strings.

Caught by coverity (#985909)

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

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

index 9fdaaf8aef1f5eb5841ced53503749b2fd27ab77..f0a57874b66a45007dd5049648c812d58a414d4f 100644 (file)
@@ -61,6 +61,7 @@
 #include <rx/xdr.h>
 #include <errno.h>
 #include <afs/auth.h>
+#include <afs/afsutil.h>
 #include "kauth.h"
 #include "kautils.h"
 #include "kauth_internal.h"
@@ -68,7 +69,6 @@
 afs_int32
 krb_write_ticket_file(char *realm)
 {
-    char ticket_file[AFSDIR_PATH_MAX];
     int fd;
     int count;
     afs_int32 code;
@@ -91,10 +91,15 @@ krb_write_ticket_file(char *realm)
      * back upon /tmp/tkt(uid}.
      */
     if ((tf_name = (char *)getenv("KRBTKFILE")))
-       (void)sprintf(ticket_file, "%s", tf_name);
-    else
-       (void)sprintf(ticket_file, "%s/tkt%d", gettmpdir(), getuid());
-    fd = open(ticket_file, O_WRONLY + O_CREAT + O_TRUNC, 0700);
+       fd = open(tf_name, O_WRONLY | O_CREAT | O_TRUNC, 0700);
+    else {
+       afs_asprintf(&tf_name, "%s/tkt%d", gettmpdir(), getuid());
+       if (tf_name == NULL)
+           return ENOMEM;
+       fd = open(tf_name, O_WRONLY | O_CREAT | O_TRUNC, 0700);
+       free(tf_name);
+    }
+
     if (fd <= 0)
        return errno;