bos: Don't overflow buffer with key data
authorSimon Wilkinson <sxw@your-file-system.com>
Fri, 8 Mar 2013 13:02:26 +0000 (13:02 +0000)
committerDerrick Brashear <shadow@your-file-system.com>
Tue, 12 Mar 2013 13:51:42 +0000 (06:51 -0700)
When parsing key data from the command line, don't overflow the
buffer used to hold it - instead just give an error if the data
is too long.

Caught by coverity (#985775)

Change-Id: I44fb62d30c5022e650475b3ca51a28bcb7cf1e06
Reviewed-on: http://gerrit.openafs.org/9550
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/bozo/bos.c

index 5e951a9..1e366d1 100644 (file)
@@ -793,9 +793,12 @@ AddKey(struct cmd_syndesc *as, void *arock)
     tconn = GetConn(as, 1);
     memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
 
-    if (as->parms[1].items)
-       strcpy(buf, as->parms[1].items->data);
-    else {
+    if (as->parms[1].items) {
+       if (strlcpy(buf, as->parms[1].items->data, sizeof(buf)) >= sizeof(buf)) {
+           fprintf(stderr, "Key data too long for buffer\n");
+           exit(1);
+       }
+    } else {
        /* prompt for key */
        code = UI_UTIL_read_pw_string(buf, sizeof(buf), "input key: ", 0);
        if (code || strlen(buf) == 0) {