From d527a8082507bf091f89c7964ce152dfce5d4052 Mon Sep 17 00:00:00 2001 From: Jeffrey Hutzelman Date: Sat, 15 Jun 2013 18:58:13 -0400 Subject: [PATCH] Fix unchecked calls to asprintf 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 Reviewed-by: D Brashear Tested-by: BuildBot --- src/afsd/afsd_fuse.c | 48 ++++++++++++++++++++- src/afsweb/apache_afs_plugin.c | 3 +- src/aklog/aklog.c | 26 +++++++---- src/audit/audit-file.c | 6 +-- src/auth/cellconfig.c | 30 ++++++++----- src/bozo/bnode.c | 6 ++- src/bozo/bosoprocs.c | 7 ++- src/bozo/bosserver.c | 9 ++-- src/budb/procs.c | 4 +- src/budb/server.c | 19 ++++---- src/cmd/cmd.c | 24 +++++------ src/kauth/krb_tf.c | 4 +- src/platform/DARWIN/AklogAuthPlugin/aklog.c | 3 +- src/ptserver/db_verify.c | 3 +- src/ptserver/ptutils.c | 3 +- src/sys/rmtsysc.c | 4 +- src/tests/create-stat.c | 3 +- src/util/dirpath.c | 3 +- tests/cmd/command-t.c | 17 +++++--- tests/common/servers.c | 9 ++-- tests/volser/vos-t.c | 5 ++- 21 files changed, 162 insertions(+), 74 deletions(-) diff --git a/src/afsd/afsd_fuse.c b/src/afsd/afsd_fuse.c index 03a801ac9..7b3968b79 100644 --- a/src/afsd/afsd_fuse.c +++ b/src/afsd/afsd_fuse.c @@ -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); diff --git a/src/afsweb/apache_afs_plugin.c b/src/afsweb/apache_afs_plugin.c index 8ead201c0..94bd5f067 100644 --- a/src/afsweb/apache_afs_plugin.c +++ b/src/afsweb/apache_afs_plugin.c @@ -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", diff --git a/src/aklog/aklog.c b/src/aklog/aklog.c index c9f9cfe53..f7b131320 100644 --- a/src/aklog/aklog.c +++ b/src/aklog/aklog.c @@ -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 diff --git a/src/audit/audit-file.c b/src/audit/audit-file.c index e03193f2b..875c10f0b 100644 --- a/src/audit/audit-file.c +++ b/src/audit/audit-file.c @@ -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; } diff --git a/src/auth/cellconfig.c b/src/auth/cellconfig.c index 11c51cddc..7f7aaaf43 100644 --- a/src/auth/cellconfig.c +++ b/src/auth/cellconfig.c @@ -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; diff --git a/src/bozo/bnode.c b/src/bozo/bnode.c index 077a446f0..d117311bd 100644 --- a/src/bozo/bnode.c +++ b/src/bozo/bnode.c @@ -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; } diff --git a/src/bozo/bosoprocs.c b/src/bozo/bosoprocs.c index 20dd956bf..b625ac079 100644 --- a/src/bozo/bosoprocs.c +++ b/src/bozo/bosoprocs.c @@ -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: diff --git a/src/bozo/bosserver.c b/src/bozo/bosserver.c index c8ddc770b..694fd7616 100644 --- a/src/bozo/bosserver.c +++ b/src/bozo/bosserver.c @@ -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); } diff --git a/src/budb/procs.c b/src/budb/procs.c index d3d828391..f2987d311 100644 --- a/src/budb/procs.c +++ b/src/budb/procs.c @@ -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"); diff --git a/src/budb/server.c b/src/budb/server.c index c6e11f5fb..c8dd504f1 100644 --- a/src/budb/server.c +++ b/src/budb/server.c @@ -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 */ diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index f97e558f0..e2e8e3a08 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -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(§ion, "%s_%s", commandName, syn->name); + if (asprintf(§ion, "%s_%s", commandName, syn->name) < 0) + return ENOMEM; *str = cmd_RawConfigGetString(globalConfig, NULL, section, optionName, NULL); free(section); diff --git a/src/kauth/krb_tf.c b/src/kauth/krb_tf.c index 1ccb76752..08a1db992 100644 --- a/src/kauth/krb_tf.c +++ b/src/kauth/krb_tf.c @@ -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); diff --git a/src/platform/DARWIN/AklogAuthPlugin/aklog.c b/src/platform/DARWIN/AklogAuthPlugin/aklog.c index 726db3a1d..1c8e05a86 100644 --- a/src/platform/DARWIN/AklogAuthPlugin/aklog.c +++ b/src/platform/DARWIN/AklogAuthPlugin/aklog.c @@ -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 diff --git a/src/ptserver/db_verify.c b/src/ptserver/db_verify.c index c28c4437e..fd7aa9f26 100644 --- a/src/ptserver/db_verify.c +++ b/src/ptserver/db_verify.c @@ -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; diff --git a/src/ptserver/ptutils.c b/src/ptserver/ptutils.c index df8caf069..7d0ca1e8e 100644 --- a/src/ptserver/ptutils.c +++ b/src/ptserver/ptutils.c @@ -409,7 +409,8 @@ CreateEntry(struct ubik_trans *at, char aname[PR_MAXNAMELEN], afs_int32 *aid, af /* To create the user @ the group AUTHUSER_GROUP@ * must exist. */ - asprintf(&cellGroup, "%s%s", AUTHUSER_GROUP, atsign); + if (asprintf(&cellGroup, "%s%s", AUTHUSER_GROUP, atsign) < 0) + return PRNOMEM; pos = FindByName(at, cellGroup, ¢ry); free(cellGroup); if (!pos) diff --git a/src/sys/rmtsysc.c b/src/sys/rmtsysc.c index 3e22aa720..0893a9863 100644 --- a/src/sys/rmtsysc.c +++ b/src/sys/rmtsysc.c @@ -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); diff --git a/src/tests/create-stat.c b/src/tests/create-stat.c index acd12e795..a7a45607b 100644 --- a/src/tests/create-stat.c +++ b/src/tests/create-stat.c @@ -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) diff --git a/src/util/dirpath.c b/src/util/dirpath.c index e4132ac43..03177696b 100644 --- a/src/util/dirpath.c +++ b/src/util/dirpath.c @@ -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; diff --git a/tests/cmd/command-t.c b/tests/cmd/command-t.c index 19c9f7f93..796ff22c7 100644 --- a/tests/cmd/command-t.c +++ b/tests/cmd/command-t.c @@ -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"); diff --git a/tests/common/servers.c b/tests/common/servers.c index a2a4e697d..4380e57c3 100644 --- a/tests/common/servers.c +++ b/tests/common/servers.c @@ -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); diff --git a/tests/volser/vos-t.c b/tests/volser/vos-t.c index 3919c0b69..a93dfc6e2 100644 --- a/tests/volser/vos-t.c +++ b/tests/volser/vos-t.c @@ -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); -- 2.39.5