]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Fix unchecked calls to asprintf
authorJeffrey Hutzelman <jhutz@cmu.edu>
Sat, 15 Jun 2013 22:58:13 +0000 (18:58 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Mon, 1 Dec 2014 16:27:15 +0000 (11:27 -0500)
The return value of asprintf() is the number of bytes printed, or -1 if there
was an error allocating a large enough buffer.  In the latter case, the value
of the result string is undefined, and so it cannot be counted on to be NULL.

This change fixes numerous places where the result of asprintf is checked
incorrectly (by examining the output pointer and not the return value) or not
at all.

Change-Id: I9fef14d60c096795d59c42798f3906041fb18c86
Reviewed-on: http://gerrit.openafs.org/9978
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: D Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
21 files changed:
src/afsd/afsd_fuse.c
src/afsweb/apache_afs_plugin.c
src/aklog/aklog.c
src/audit/audit-file.c
src/auth/cellconfig.c
src/bozo/bnode.c
src/bozo/bosoprocs.c
src/bozo/bosserver.c
src/budb/procs.c
src/budb/server.c
src/cmd/cmd.c
src/kauth/krb_tf.c
src/platform/DARWIN/AklogAuthPlugin/aklog.c
src/ptserver/db_verify.c
src/ptserver/ptutils.c
src/sys/rmtsysc.c
src/tests/create-stat.c
src/util/dirpath.c
tests/cmd/command-t.c
tests/common/servers.c
tests/volser/vos-t.c

index 03a801ac90a891b45512cc30862819fb4ba808a7..7b3968b79dc7026d8a20c4a1cdb98959463bc0cb 100644 (file)
@@ -77,7 +77,8 @@ afs_path(const char *apath)
     static const char prefix[] = "/afs/";
     char *path;
 
-    asprintf(&path, "%s%s", prefix, apath);
+    if (asprintf(&path, "%s%s", prefix, apath) < 0)
+       path = NULL;
 
     return path;
 }
@@ -100,6 +101,9 @@ fuafsd_getattr(const char *apath, struct stat *stbuf)
        int code;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        code = uafs_lstat(path, stbuf);
 
        free(path);
@@ -116,6 +120,9 @@ fuafsd_opendir(const char *apath, struct fuse_file_info * fi)
        usr_DIR * dirp;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        dirp = uafs_opendir(path);
 
        free(path);
@@ -161,6 +168,9 @@ fuafsd_create(const char *apath, mode_t mode, struct fuse_file_info * fi)
        int fd;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        fd = uafs_open(path, fi->flags, mode);
 
        free(path);
@@ -202,6 +212,9 @@ fuafsd_readlink(const char *apath, char * buf, size_t len)
        int code;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        code = uafs_readlink(path, buf, len);
 
        free(path);
@@ -221,6 +234,9 @@ fuafsd_mkdir(const char *apath, mode_t mode)
        int code;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        code = uafs_mkdir(path, mode);
 
        free(path);
@@ -237,6 +253,9 @@ fuafsd_unlink(const char *apath)
        int code;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        code = uafs_unlink(path);
 
        free(path);
@@ -253,6 +272,9 @@ fuafsd_rmdir(const char *apath)
        int code;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        code = uafs_rmdir(path);
 
        free(path);
@@ -270,6 +292,12 @@ fuafsd_symlink(const char *atarget, const char *asource)
        char *target = afs_path(atarget);
        char *source = afs_path(asource);
 
+       if (target == NULL || source == NULL) {
+           if (target) free(target);
+           if (source) free(source);
+           return -ENOMEM;
+       }
+
        code = uafs_symlink(target, source);
 
        free(target);
@@ -288,6 +316,12 @@ fuafsd_rename(const char *aold, const char *anew)
        char *old = afs_path(aold);
        char *new = afs_path(anew);
 
+       if (old == NULL || new == NULL) {
+           if (old) free(old);
+           if (new) free(new);
+           return -ENOMEM;
+       }
+
        code = uafs_rename(old, new);
 
        free(old);
@@ -306,6 +340,12 @@ fuafsd_link(const char *aexisting, const char *anew)
        char *existing = afs_path(aexisting);
        char *new = afs_path(anew);
 
+       if (existing == NULL || new == NULL) {
+           if (existing) free(existing);
+           if (new) free(new);
+           return -ENOMEM;
+       }
+
        code = uafs_link(existing, new);
 
        free(existing);
@@ -323,6 +363,9 @@ fuafsd_chmod(const char *apath, mode_t mode)
        int code;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        code = uafs_chmod(path, mode);
 
        free(path);
@@ -339,6 +382,9 @@ fuafsd_truncate(const char *apath, off_t length)
        int code;
        char *path = afs_path(apath);
 
+       if (path == NULL)
+           return -ENOMEM;
+
        code = uafs_truncate(path, length);
 
        free(path);
index 8ead201c0836178620ac9dc797c896768d07e19f..94bd5f067a53bf724579859a928ad2735f802a1a 100644 (file)
@@ -98,7 +98,8 @@ afs_plugin_init(int tokenExpiration, char *weblogPath, char *error_fname,
                module_name);
        exit(-1);
     }
-    asprintf(&afs_weblog_pidfile, "%s.afs", httpd_pid_fname);
+    if (asprintf(&afs_weblog_pidfile, "%s.afs", httpd_pid_fname) < 0)
+       afs_weblog_pidfile == NULL;
     if (afs_weblog_pidfile == NULL) {
        fprintf(stderr,
                "%s: malloc failed - out of memory while allocating space for afs_weblog_pidfile\n",
index c9f9cfe5312348623c0ff682c38d4a00f3f5528a..f7b13132041c2a9e80191f74ce5a7d6fe0412f1b 100644 (file)
@@ -881,7 +881,12 @@ rxkad_get_token(krb5_context context, struct afsconf_cell *cell, char *realm,
        username = NULL;
        *foreign = 0;
     } else {
-       asprintf(authuser, "%s@%s", username, realmUsed);
+       if (asprintf(authuser, "%s@%s", username, realmUsed) < 0) {
+           fprintf(stderr, "%s: Out of memory building PTS name\n", progname);
+           *authuser = NULL;
+           status = AKLOG_MISC;
+           goto out;
+       }
        *foreign = 1;
     }
 
@@ -1492,20 +1497,25 @@ main(int argc, char *argv[])
        filepath = getenv("KRB5_CONFIG");
 
        /* only fiddle with KRB5_CONFIG if krb5-weak.conf actually exists */
-       asprintf(&newpath, "%s/krb5-weak.conf", AFSDIR_CLIENT_ETC_DIRPATH);
-       if (access(newpath, R_OK) == 0) {
+       if (asprintf(&newpath, "%s/krb5-weak.conf",
+                    AFSDIR_CLIENT_ETC_DIRPATH) < 0)
+           newpath = NULL;
+       if (newpath != NULL && access(newpath, R_OK) == 0) {
            free(newpath);
            newpath = NULL;
-           asprintf(&newpath, "%s:%s/krb5-weak.conf",
-                    filepath ? filepath : defaultpath,
-                    AFSDIR_CLIENT_ETC_DIRPATH);
-           setenv("KRB5_CONFIG", newpath, 1);
+           if (asprintf(&newpath, "%s:%s/krb5-weak.conf",
+                        filepath ? filepath : defaultpath,
+                        AFSDIR_CLIENT_ETC_DIRPATH) < 0)
+               newpath = NULL;
+           else
+               setenv("KRB5_CONFIG", newpath, 1);
        }
 #endif
        krb5_init_context(&context);
 
 #if defined(KRB5_PROG_ETYPE_NOSUPP) && !(defined(HAVE_KRB5_ENCTYPE_ENABLE) || defined(HAVE_KRB5_ALLOW_WEAK_CRYPTO))
-       free(newpath);
+       if (newpath)
+           free(newpath);
        if (filepath)
            setenv("KRB5_CONFIG", filepath, 1);
        else
index e03193f2b3f1c3842f4b8ac396863fd8eeb3a9aa..875c10f0ba1a17145872c08863a7ae0679a17e9c 100644 (file)
@@ -38,7 +38,7 @@ append_msg(const char *format, ...)
 static int
 open_file(const char *fileName)
 {
-    int tempfd, flags;
+    int tempfd, flags, r;
     char *oldName;
 
 #ifndef AFS_NT40_ENV
@@ -50,8 +50,8 @@ open_file(const char *fileName)
     } else
 #endif
     {
-       asprintf(&oldName, "%s.old", fileName);
-       if (oldName == NULL) {
+       r = asprintf(&oldName, "%s.old", fileName);
+       if (r < 0 || oldName == NULL) {
            printf("Warning: Unable to create backup filename. Auditing ignored\n");
            return 1;
        }
index 11c51cddc663eb18b5742d32861bf69272a109e1..7f7aaaf43b05532e4d39c6999f6cd5eef7f4eca6 100644 (file)
@@ -327,13 +327,17 @@ _afsconf_CellServDBPath(struct afsconf_dir *adir, char **path)
     /* NT client CellServDB has different file name than NT server or Unix */
     if (_afsconf_IsClientConfigDirectory(adir->name)) {
        if (!afssw_GetClientCellServDBDir(&p)) {
-           asprintf(path, "%s/%s", p, AFSDIR_CELLSERVDB_FILE_NTCLIENT);
+           if (asprintf(path, "%s/%s", p, AFSDIR_CELLSERVDB_FILE_NTCLIENT) < 0)
+               *path = NULL;
            free(p);
        } else {
-           asprintf(path, "%s/%s", adir->name, AFSDIR_CELLSERVDB_FILE_NTCLIENT);
+           if (asprintf(path, "%s/%s", adir->name,
+                        AFSDIR_CELLSERVDB_FILE_NTCLIENT) < 0)
+               *path = NULL;
        }
     } else {
-       asprintf(path, "%s/%s", adir->name, AFSDIR_CELLSERVDB_FILE);
+       if (asprintf(path, "%s/%s", adir->name, AFSDIR_CELLSERVDB_FILE) < 0)
+           *path = NULL;
     }
     return;
 }
@@ -341,7 +345,8 @@ _afsconf_CellServDBPath(struct afsconf_dir *adir, char **path)
 static void
 _afsconf_CellServDBPath(struct afsconf_dir *adir, char **path)
 {
-    asprintf(path, "%s/%s", adir->name, AFSDIR_CELLSERVDB_FILE);
+    if (asprintf(path, "%s/%s", adir->name, AFSDIR_CELLSERVDB_FILE) < 0)
+       *path = NULL;
 }
 #endif /* AFS_NT40_ENV */
 
@@ -449,6 +454,7 @@ afsconf_Open(const char *adir)
            char *home_dir;
            afsconf_FILE *fp;
            size_t len;
+           int r;
 
            if (!(home_dir = getenv("HOME"))) {
                /* Our last chance is the "/.AFSCONF" file */
@@ -461,8 +467,8 @@ afsconf_Open(const char *adir)
            } else {
                char *pathname = NULL;
 
-               asprintf(&pathname, "%s/%s", home_dir, ".AFSCONF");
-               if (pathname == NULL)
+               r = asprintf(&pathname, "%s/%s", home_dir, ".AFSCONF");
+               if (r < 0 || pathname == NULL)
                    goto fail;
 
                fp = fopen(pathname, "r");
@@ -965,6 +971,7 @@ afsconf_LookupServer(const char *service, const char *protocol,
                     int *numServers, int *ttl, char **arealCellName)
 {
     int code = 0;
+    int r;
     int len;
     unsigned char answer[4096];
     unsigned char *p;
@@ -1002,25 +1009,26 @@ afsconf_LookupServer(const char *service, const char *protocol,
 #endif
 
  retryafsdb:
+    r = -1;
     switch (pass) {
     case 0:
        dnstype = T_SRV;
-       asprintf(&dotcellname, "_%s._%s.%s.", IANAname, protocol, cellName);
+       r = asprintf(&dotcellname, "_%s._%s.%s.", IANAname, protocol, cellName);
        break;
     case 1:
        dnstype = T_AFSDB;
-       asprintf(&dotcellname, "%s.", cellName);
+       r = asprintf(&dotcellname, "%s.", cellName);
        break;
     case 2:
        dnstype = T_SRV;
-       asprintf(&dotcellname, "_%s._%s.%s", IANAname, protocol, cellName);
+       r = asprintf(&dotcellname, "_%s._%s.%s", IANAname, protocol, cellName);
        break;
     case 3:
        dnstype = T_AFSDB;
-       asprintf(&dotcellname, "%s", cellName);
+       r = asprintf(&dotcellname, "%s", cellName);
        break;
     }
-    if (dotcellname == NULL)
+    if (r < 0 || dotcellname == NULL)
        goto findservererror;
 
     LOCK_GLOBAL_MUTEX;
index 077a446f0fbc2e3457a2c584e7cc026f05751d93..d117311bd6e83fffad3f163ddbd501ea14a4951d 100644 (file)
@@ -126,8 +126,10 @@ SaveCore(struct bnode *abnode, struct bnode_proc
                 continue;
             pid = atol(file->d_name + 5);
             if (pid == aproc->pid) {
-                asprintf(&corefile, "%s/%s", coredir, file->d_name);
-                if (corefile == NULL) {
+                int r;
+
+                r = asprintf(&corefile, "%s/%s", coredir, file->d_name);
+                if (r < 0 || corefile == NULL) {
                     closedir(logdir);
                     return;
                 }
index 20dd956bff14f0417808c1a1803efe75c372d47d..b625ac0798f11d2c1f66b28a848611793c1fbae1 100644 (file)
@@ -427,9 +427,14 @@ SBOZO_GetCellHost(struct rx_call *acall, afs_uint32 awhich, char **aname)
 
     tp = tcell.hostName[awhich];
     if (clones[awhich]) {
-       asprintf(aname, "[%s]", tp);
+       if (asprintf(aname, "[%s]", tp) < 0)
+           *aname = NULL;
     } else
        *aname = strdup(tp);
+    if (*aname == NULL) {
+       code = BZIO;
+       goto fail;
+    }
     goto done;
 
   fail:
index c8ddc770be66c71ea421af99958e13ea6e49cb1e..694fd7616215d854c43eab92a147a643b15b91be 100644 (file)
@@ -645,15 +645,16 @@ static char *
 make_pid_filename(char *ainst, char *aname)
 {
     char *buffer = NULL;
+    int r;
 
     if (aname && *aname) {
-       asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
-       if (buffer == NULL)
+       r = asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
+       if (r < 0 || buffer == NULL)
            bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
                     ainst, aname);
     } else {
-       asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
-       if (buffer == NULL)
+       r = asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
+       if (r < 0 || buffer == NULL)
            bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
     }
 
index d3d828391b31e02a937b37a1298f5182c1659650..f2987d3115cfb07ad08d37bd744ea686d66355c1 100644 (file)
@@ -3530,8 +3530,8 @@ T_DumpDatabase(struct rx_call *call, char *filename)
     if (!callPermitted(call))
        return BUDB_NOTPERMITTED;
 
-    asprintf(&path, "%s/%s", gettmpdir(), filename);
-    if (!path)
+    length = asprintf(&path, "%s/%s", gettmpdir(), filename);
+    if (length < 0 || !path)
        return (BUDB_INTERNALERROR);
 
     dumpfid = fopen(path, "w");
index c6e11f5fb38885943a514a7b99c33f2a1fed0568..c8dd504f1b336ab8c0bc3ec9600aff2c10b8c4d2 100644 (file)
@@ -322,13 +322,13 @@ truncateDatabase(void)
 {
     char *path;
     afs_int32 code = 0;
-    int fd;
+    int fd,r;
 
-    asprintf(&path, "%s%s%s",
-            globalConfPtr->databaseDirectory,
-            globalConfPtr->databaseName,
-            globalConfPtr->databaseExtension);
-    if (path == NULL)
+    r = asprintf(&path, "%s%s%s",
+                globalConfPtr->databaseDirectory,
+                globalConfPtr->databaseName,
+                globalConfPtr->databaseExtension);
+    if (r < 0 || path == NULL)
        ERROR(-1);
 
     fd = open(path, O_RDWR, 0755);
@@ -362,6 +362,7 @@ main(int argc, char **argv)
     time_t currentTime;
     afs_int32 code = 0;
     afs_uint32 host = ntohl(INADDR_ANY);
+    int r;
 
     char  clones[MAXHOSTSPERCELL];
 
@@ -495,9 +496,9 @@ main(int argc, char **argv)
 
     LogError(0, "Will allocate %d ubik buffers\n", ubik_nBuffers);
 
-    asprintf(&dbNamePtr, "%s%s", globalConfPtr->databaseDirectory,
-            globalConfPtr->databaseName);
-    if (dbNamePtr == 0)
+    r = asprintf(&dbNamePtr, "%s%s", globalConfPtr->databaseDirectory,
+                globalConfPtr->databaseName);
+    if (r < 0 || dbNamePtr == 0)
        ERROR(-1);
 
     rx_SetRxDeadTime(60);      /* 60 seconds inactive before timeout */
index f97e558f0e9ae014cdce85e24eea2d8eacaf38a7..e2e8e3a089f4f0558aa0dfbfb2c68b5bc6d0367a 100644 (file)
@@ -171,11 +171,12 @@ ParmHelpString(struct cmd_parmdesc *aparm)
     if (aparm->type == CMD_FLAG) {
        return strdup("");
     } else {
-       asprintf(&str, " %s<%s>%s%s",
-                aparm->type == CMD_SINGLE_OR_FLAG?"[":"",
-                aparm->help?aparm->help:"arg",
-                aparm->type == CMD_LIST?"+":"",
-                aparm->type == CMD_SINGLE_OR_FLAG?"]":"");
+       if (asprintf(&str, " %s<%s>%s%s",
+                    aparm->type == CMD_SINGLE_OR_FLAG?"[":"",
+                    aparm->help?aparm->help:"arg",
+                    aparm->type == CMD_LIST?"+":"",
+                    aparm->type == CMD_SINGLE_OR_FLAG?"]":"") < 0)
+           return "<< OUT OF MEMORY >>";
        return str;
     }
 }
@@ -201,18 +202,14 @@ PrintSyntax(struct cmd_syndesc *as)
 
     /* now print usage, from syntax table */
     if (noOpcodes)
-       asprintf(&str, "Usage: %s", as->a0name);
+       len = printf("Usage: %s", as->a0name);
     else {
        if (!strcmp(as->name, initcmd_opcode))
-           asprintf(&str, "Usage: %s[%s]", NName(as->a0name, " "), as->name);
+           len = printf("Usage: %s[%s]", NName(as->a0name, " "), as->name);
        else
-           asprintf(&str, "Usage: %s%s", NName(as->a0name, " "), as->name);
+           len = printf("Usage: %s%s", NName(as->a0name, " "), as->name);
     }
 
-    len = strlen(str);
-    printf("%s", str);
-    free(str);
-
     for (i = 0; i < CMD_MAXPARMS; i++) {
        tp = &as->parms[i];
        if (tp->type == 0)
@@ -1272,7 +1269,8 @@ _get_file_string(struct cmd_syndesc *syn, int pos, const char **str)
 
     /* First, try the command_subcommand form */
     if (syn->name != NULL && commandName != NULL) {
-       asprintf(&section, "%s_%s", commandName, syn->name);
+       if (asprintf(&section, "%s_%s", commandName, syn->name) < 0)
+           return ENOMEM;
        *str = cmd_RawConfigGetString(globalConfig, NULL, section,
                                      optionName, NULL);
        free(section);
index 1ccb767523c6128eed7ea53b927323ba4dcb43c4..08a1db992b4c2832749cea37d6abccdb7d97f554 100644 (file)
@@ -84,8 +84,8 @@ krb_write_ticket_file(char *realm)
     if ((tf_name = (char *)getenv("KRBTKFILE")))
        fd = open(tf_name, O_WRONLY | O_CREAT | O_TRUNC, 0700);
     else {
-       asprintf(&tf_name, "%s/tkt%d", gettmpdir(), getuid());
-       if (tf_name == NULL)
+       count = asprintf(&tf_name, "%s/tkt%d", gettmpdir(), getuid());
+       if (count < 0 || tf_name == NULL)
            return ENOMEM;
        fd = open(tf_name, O_WRONLY | O_CREAT | O_TRUNC, 0700);
        free(tf_name);
index 726db3a1d8e238d4a928bc6f4533ad5df636ef33..1c8e05a8608e6eca3013074f21c82ab5fba3d7fd 100644 (file)
@@ -57,7 +57,8 @@ static OSStatus do_aklog(char *cell)
 
     char *aklogCmd;
     if (cell) {
-       asprintf(&aklogCmd, "/usr/bin/aklog %s", cell);
+       if (asprintf(&aklogCmd, "/usr/bin/aklog %s", cell) < 0)
+           aklogCmd = NULL;
        if (aklogCmd)
            return system(aklogCmd);
        else
index c28c4437e047ab0cf80b3a1a0de8ce48bde5bd51..fd7aa9f26aaff52bb9cf66023e6a909ddc079f3f 100644 (file)
@@ -958,7 +958,8 @@ QuoteName(char *s)
 {
     char *qs;
     if (strpbrk(s, " \t")) {
-       asprintf(&qs, "\"%s\"", s);
+       if (asprintf(&qs, "\"%s\"", s) < 0)
+           qs = "<<-OUT-OF-MEMORY->>";
     } else
        qs = s;
     return qs;
index df8caf069eea3891d18dfd1a7e64ff0aa2890266..7d0ca1e8ee5988b30ec806b87363d414b10e75b8 100644 (file)
@@ -409,7 +409,8 @@ CreateEntry(struct ubik_trans *at, char aname[PR_MAXNAMELEN], afs_int32 *aid, af
        /* To create the user <name>@<cell> the group AUTHUSER_GROUP@<cell>
         * must exist.
         */
-       asprintf(&cellGroup, "%s%s", AUTHUSER_GROUP, atsign);
+       if (asprintf(&cellGroup, "%s%s", AUTHUSER_GROUP, atsign) < 0)
+           return PRNOMEM;
        pos = FindByName(at, cellGroup, &centry);
        free(cellGroup);
        if (!pos)
index 3e22aa720c117b2320dff04113853fa660dda380..0893a9863faf46094fd467b052bbd8f8a1182f7d 100644 (file)
@@ -70,8 +70,8 @@ GetAfsServerAddr(char *syscall)
        } else {
            char *pathname;
 
-           asprintf(&pathname, "%s/%s", home_dir, ".AFSSERVER");
-           if (pathname == NULL)
+           len = asprintf(&pathname, "%s/%s", home_dir, ".AFSSERVER");
+           if (len < 0 || pathname == NULL)
                return 0;
            fp = fopen(pathname, "r");
            free(pathname);
index acd12e7950c029e5264e127220c15bdbe04fd4ad..a7a45607bd72b8dde438a53280ceb6346095b259 100644 (file)
@@ -76,7 +76,8 @@ main(int argc, char **argv)
 
     file = argv[1];
 
-    asprintf(&filename, "%s.new", file);
+    if (asprintf(&filename, "%s.new", file) < 0)
+       err(1, "asprintf");
 
     ret = open(file, O_RDWR, 0600);
     if (ret < 0)
index e4132ac432a59a94fc086e6605f21863618e9c69..03177696b2ac7bad47f0db5ef777bc5fa0e620a3 100644 (file)
@@ -649,7 +649,8 @@ ConstructLocalPath(const char *cpath, const char *relativeTo,
     if (*cpath == '/') {
        newPath = strdup(cpath);
     } else {
-       asprintf(&newPath, "%s/%s", relativeTo, cpath);
+       if (asprintf(&newPath, "%s/%s", relativeTo, cpath) < 0)
+           newPath = NULL;
     }
     if (newPath == NULL)
        status = ENOMEM;
index 19c9f7f93dfe7b93b4c45dd46d7f11767bfe27a0..796ff22c7e584c378fd8e533c93436e317eeef51 100644 (file)
@@ -362,12 +362,17 @@ main(int argc, char **argv)
     /* Now, try adding a configuration file into the mix */
     if (getenv("SOURCE") == NULL)
        path = strdup("test1.conf");
-    else
-       asprintf(&path, "%s/cmd/test1.conf", getenv("SOURCE"));
-
-    cmd_SetCommandName("test");
-    code = cmd_OpenConfigFile(path);
-    is_int(0, code, "cmd_OpenConfigFile succeeds");
+    else {
+       if (asprintf(&path, "%s/cmd/test1.conf", getenv("SOURCE")) < 0)
+           path = NULL;
+    }
+    if (path != NULL) {
+       cmd_SetCommandName("test");
+       code = cmd_OpenConfigFile(path);
+       is_int(0, code, "cmd_OpenConfigFile succeeds");
+    } else {
+       skip("no memory to build config file path");
+    }
 
     code = cmd_ParseLine("-first 1", tv, &tc, 100);
     is_int(0, code, "cmd_ParseLine succeeds");
index a2a4e697d2743175096cbfc5da1b2b87a93f4878..4380e57c35e94e442386df8aa2ab2abfb36367cc 100644 (file)
@@ -35,9 +35,12 @@ afstest_StartVLServer(char *dirname, pid_t *serverPid)
        if (build == NULL)
            build = "..";
 
-       asprintf(&binPath, "%s/../src/tvlserver/vlserver", build);
-       asprintf(&logPath, "%s/VLLog", dirname);
-       asprintf(&dbPath, "%s/vldb", dirname);
+       if (asprintf(&binPath, "%s/../src/tvlserver/vlserver", build) < 0 ||
+           asprintf(&logPath, "%s/VLLog", dirname) < 0 ||
+           asprintf(&dbPath, "%s/vldb", dirname) < 0) {
+           fprintf(stderr, "Out of memory building vlserver arguments\n");
+           exit(1);
+       }
        execl(binPath, "vlserver",
              "-logfile", logPath, "-database", dbPath, "-config", dirname, NULL);
        fprintf(stderr, "Running %s failed\n", binPath);
index 3919c0b6926904e06af103da9126c3f15a18610a..a93dfc6e2a0fade7bc2b7672ffae6f7513ff15e3 100644 (file)
@@ -70,7 +70,10 @@ TestListAddrs(struct ubik_client *client, char *dirname)
        if (build == NULL)
            build = "..";
 
-       asprintf(&binPath, "%s/../src/volser/vos", build);
+       if (asprintf(&binPath, "%s/../src/volser/vos", build) < 0) {
+           fprintf(stderr, "Out of memory building vos arguments\n");
+           exit(1);
+       }
        execl(binPath, "vos",
              "listaddrs", "-config", dirname, "-noauth", NULL);
        exit(1);