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;
}
int code;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
code = uafs_lstat(path, stbuf);
free(path);
usr_DIR * dirp;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
dirp = uafs_opendir(path);
free(path);
int fd;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
fd = uafs_open(path, fi->flags, mode);
free(path);
int code;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
code = uafs_readlink(path, buf, len);
free(path);
int code;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
code = uafs_mkdir(path, mode);
free(path);
int code;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
code = uafs_unlink(path);
free(path);
int code;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
code = uafs_rmdir(path);
free(path);
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);
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);
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);
int code;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
code = uafs_chmod(path, mode);
free(path);
int code;
char *path = afs_path(apath);
+ if (path == NULL)
+ return -ENOMEM;
+
code = uafs_truncate(path, length);
free(path);
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",
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;
}
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
static int
open_file(const char *fileName)
{
- int tempfd, flags;
+ int tempfd, flags, r;
char *oldName;
#ifndef AFS_NT40_ENV
} 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;
}
/* 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;
}
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 */
char *home_dir;
afsconf_FILE *fp;
size_t len;
+ int r;
if (!(home_dir = getenv("HOME"))) {
/* Our last chance is the "/.AFSCONF" file */
} 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");
int *numServers, int *ttl, char **arealCellName)
{
int code = 0;
+ int r;
int len;
unsigned char answer[4096];
unsigned char *p;
#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;
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;
}
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:
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);
}
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");
{
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);
time_t currentTime;
afs_int32 code = 0;
afs_uint32 host = ntohl(INADDR_ANY);
+ int r;
char clones[MAXHOSTSPERCELL];
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 */
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;
}
}
/* 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)
/* 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);
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);
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
{
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;
/* 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, ¢ry);
free(cellGroup);
if (!pos)
} 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);
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)
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;
/* 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");
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);
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);