static char *
afs_path(const char *apath)
{
- size_t len;
static const char prefix[] = "/afs/";
char *path;
- len = strlen(apath) + sizeof(prefix);
-
- path = malloc(len);
-
- sprintf(path, "%s%s", prefix, apath);
+ asprint(&path, "%s%s", prefix, apath);
return path;
}
module_name);
exit(-1);
}
- afs_weblog_pidfile = (char *)malloc(strlen(httpd_pid_fname) + 5);
- if (httpd_pid_fname == NULL) {
+ asprintf(&afs_weblog_pidfile, "%s.afs", httpd_pid_fname);
+ if (afs_weblog_pidfile == NULL) {
fprintf(stderr,
"%s: malloc failed - out of memory while allocating space for afs_weblog_pidfile\n",
module_name);
exit(-1);
}
- sprintf(afs_weblog_pidfile, "%s.afs", httpd_pid_fname);
if (do_setpag()) {
fprintf(stderr, "%s:Failed to set pag Error:%d\n", module_name,
char *realmUsed = NULL;
char *username = NULL;
int status;
- size_t len;
*token = NULL;
*authuser = NULL;
username = NULL;
*foreign = 0;
} else {
- len = strlen(username)+strlen(realmUsed)+2;
- *authuser = malloc(len);
- snprintf(*authuser, len, "%s@%s", username, realmUsed);
+ asprintf(authuser, "%s@%s", username, realmUsed);
*foreign = 1;
}
if (code) {
DIR *logdir;
struct dirent *file;
- size_t length;
unsigned long pid;
const char *coredir = AFSDIR_LOGS_DIR;
continue;
pid = atol(file->d_name + 5);
if (pid == aproc->pid) {
- length = strlen(coredir) + strlen(file->d_name) + 2;
- corefile = malloc(length);
+ asprintf(&corefile, "%s/%s", coredir, file->d_name);
if (corefile == NULL) {
closedir(logdir);
return;
}
- snprintf(corefile, length, "%s/%s", coredir, file->d_name);
code = 0;
break;
}
}
tp = tcell.hostName[awhich];
- *aname = (char *)malloc(strlen(tp) + 3);
if (clones[awhich]) {
- strcpy(*aname, "[");
- strcat(*aname, tp);
- strcat(*aname, "]");
+ asprintf(aname, "[%s]", tp);
} else
- strcpy(*aname, tp);
+ *aname = strdup(tp);
goto done;
fail:
make_pid_filename(char *ainst, char *aname)
{
char *buffer = NULL;
- int length;
- length = strlen(DoPidFiles) + strlen(ainst) + 6;
if (aname && *aname) {
- length += strlen(aname) + 1;
- }
- buffer = malloc(length * sizeof(char));
- if (!buffer) {
- if (aname) {
+ asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
+ if (buffer == NULL)
bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
ainst, aname);
- } else {
- bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
- }
} else {
- if (aname && *aname) {
- snprintf(buffer, length, "%s/%s.%s.pid", DoPidFiles, ainst,
- aname);
- } else {
- snprintf(buffer, length, "%s/%s.pid", DoPidFiles, ainst);
- }
+ asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
+ if (buffer == NULL)
+ bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
}
+
return buffer;
}
if (!callPermitted(call))
return BUDB_NOTPERMITTED;
- path = (char *)malloc(strlen(gettmpdir()) + 1 + strlen(filename) + 1);
+ asprintf(&path, "%s/%s", gettmpdir(), filename);
if (!path)
return (BUDB_INTERNALERROR);
- sprintf(path, "%s/%s", gettmpdir(), filename);
-
dumpfid = fopen(path, "w");
if (!dumpfid)
return (BUDB_BADARGUMENT);
afs_int32 code = 0;
int fd;
- path = malloc(strlen(globalConfPtr->databaseDirectory) +
- strlen(globalConfPtr->databaseName) +
- strlen(globalConfPtr->databaseExtension) + 1);
+ asprintf(&path, "%s%s%s",
+ globalConfPtr->databaseDirectory,
+ globalConfPtr->databaseName,
+ globalConfPtr->databaseExtension);
if (path == NULL)
ERROR(-1);
- /* construct the database name */
- strcpy(path, globalConfPtr->databaseDirectory);
- strcat(path, globalConfPtr->databaseName);
- strcat(path, globalConfPtr->databaseExtension);
-
fd = open(path, O_RDWR, 0755);
if (!fd) {
code = errno;
LogError(0, "Will allocate %d ubik buffers\n", ubik_nBuffers);
- dbNamePtr =
- (char *)malloc(strlen(globalConfPtr->databaseDirectory) +
- strlen(globalConfPtr->databaseName) + 1);
+ asprintf(&dbNamePtr, "%s%s", globalConfPtr->databaseDirectory,
+ globalConfPtr->databaseName);
if (dbNamePtr == 0)
ERROR(-1);
- /* construct the database name */
- strcpy(dbNamePtr, globalConfPtr->databaseDirectory);
- strcat(dbNamePtr, globalConfPtr->databaseName); /* name prefix */
-
rx_SetRxDeadTime(60); /* 60 seconds inactive before timeout */
if (rxBind) {
{
char *qs;
if (strpbrk(s, " \t")) {
- qs = (char *)malloc(strlen(s) + 3);
- strcpy(qs, "\"");
- strcat(qs, s);
- strcat(qs, "\"");
+ asprintf(&qs, "\"%s\"", s);
} else
qs = s;
return qs;
/* To create the user <name>@<cell> the group AUTHUSER_GROUP@<cell>
* must exist.
*/
- cellGroup =
- (char *)malloc(strlen(AUTHUSER_GROUP) + strlen(atsign) + 1);
- strcpy(cellGroup, AUTHUSER_GROUP);
- strcat(cellGroup, atsign);
+ asprintf(&cellGroup, "%s%s", AUTHUSER_GROUP, atsign);
pos = FindByName(at, cellGroup, ¢ry);
free(cellGroup);
if (!pos)
LocalizePathHead(&cpath, &relativeTo);
if (*cpath == '/') {
newPath = strdup(cpath);
- if (!newPath)
- status = ENOMEM;
} else {
- newPath = (char *)malloc(strlen(relativeTo) + 1 + strlen(cpath) + 1);
- if (!newPath) {
- status = ENOMEM;
- } else {
- sprintf(newPath, "%s/%s", relativeTo, cpath);
- }
+ asprintf(&newPath, "%s/%s", relativeTo, cpath);
}
+ if (newPath == NULL)
+ status = ENOMEM;
if (status == 0) {
FilepathNormalize(newPath);