enum kcmd_proto protonum = *protonump;
int addrfamily = /* AF_INET */0;
- if ((cksumbuf = malloc(strlen(cmd)+strlen(remuser)+64)) == 0 ) {
+ if (asprintf(&cksumbuf, "%u:%s%s", ntohs(rport), cmd, remuser) < 0) {
fprintf(stderr, "Unable to allocate memory for checksum buffer.\n");
return(-1);
}
- sprintf(cksumbuf, "%u:", ntohs(rport));
- strcat(cksumbuf, cmd);
- strcat(cksumbuf, remuser);
cksumdat.data = cksumbuf;
cksumdat.length = strlen(cksumbuf);
if (authenticator->checksum) {
struct sockaddr_in adr;
socklen_t adr_length = sizeof(adr);
- char * chksumbuf = (char *) malloc(strlen(term)+strlen(lusername)+32);
+ char * chksumbuf;
if (getsockname(netf, (struct sockaddr *) &adr, &adr_length) != 0)
goto error_cleanup;
- if (chksumbuf == 0)
+ if (asprintf(&chksumbuf, "%u:%s%s", ntohs(adr.sin_port), term, lusername) < 0)
goto error_cleanup;
- sprintf(chksumbuf,"%u:", ntohs(adr.sin_port));
- strcat(chksumbuf,term);
- strcat(chksumbuf,lusername);
-
status = krb5_verify_checksum(bsd_context,
authenticator->checksum->checksum_type,
authenticator->checksum,
#include <limits.h>
#endif
+#include <k5-platform.h>
+
#include "ftp_var.h"
#ifdef ARG_MAX
char *base = *gpath ? gpath : ".";
char *buffer = 0;
- buffer = malloc(strlen(base) + strlen("\\*") + 1);
- if (!buffer) return;
- strcpy(buffer, base);
- strcat(buffer, "\\*");
+ if (asprintf(&buffer, "%s\\*", base) < 0) return;
hFile = FindFirstFile(buffer, &file_data);
if (hFile == INVALID_HANDLE_VALUE) {
if (!globbed)
strspl(cp, dp)
register char *cp, *dp;
{
- register char *ep = malloc((unsigned)(strlen(cp) + strlen(dp) + 1));
+ char *ep;
- if (ep == (char *)0)
+ if (asprintf(&ep, "%s%s", cp, dp) < 0)
fatal("Out of memory");
- (void) strcpy(ep, cp);
- (void) strcat(ep, dp);
return (ep);
}
#include <unistd.h>
#include <stdio.h>
#include <time.h>
+#include <k5-platform.h>
#define TKTTIMELEFT 60*10 /* ten minutes */
krb5_unparse_name( kcontext, kme, &pName );
if( cachename )
{
- pCacheName = malloc( strlen( pName ) + strlen( cachename ) + 1 );
- if( pCacheName == NULL )
+ if (asprintf(&pCacheName, "%s%s", cachename, pName) < 0)
{
kres = KRB5_CC_NOMEM;
goto fail;
}
- strcpy( pCacheName, cachename );
- strcat( pCacheName, pName );
kres = krb5_cc_resolve( kcontext, pCacheName, &kcache );
if( kres )
{
break;
case 'd':
/* now db_name is not a seperate argument. It has to be passed as part of the db_args */
- if (!db_name) {
- db_name = malloc(strlen(optarg) + sizeof("dbname="));
- } else {
- db_name = realloc(db_name, strlen(optarg) + sizeof("dbname="));
- }
-
- strcpy(db_name, "dbname=");
- strcat(db_name, optarg);
+ if (db_name)
+ free(db_name);
+ asprintf(&db_name, "dbname=%s", optarg);
db_args_size++;
{
}
if (cp != NULL)
*cp = '\0';
- princstr = (char*)malloc(strlen(canon) + 6 /* "/admin" */ +
- (realm ? 1 + strlen(realm) : 0) + 1);
- if (princstr == NULL) {
+ if (asprintf(&princstr, "%s/admin%s%s", canon,
+ (realm) ? "@" : "",
+ (realm) ? realm : "") < 0) {
fprintf(stderr, "%s: out of memory\n", whoami);
exit(1);
}
- strcpy(princstr, canon);
- strcat(princstr, "/admin");
- if (realm) {
- strcat(princstr, "@");
- strcat(princstr, realm);
- }
free(canon);
krb5_free_principal(context, princ);
freeprinc++;
} else if ((luser = getenv("USER"))) {
- princstr = (char *) malloc(strlen(luser) + 7 /* "/admin@" */
- + strlen(def_realm) + 1);
- if (princstr == NULL) {
+ if (asprintf(&princstr, "%s/admin@%s", luser, def_realm) < 0) {
fprintf(stderr, "%s: out of memory\n", whoami);
exit(1);
}
- strcpy(princstr, luser);
- strcat(princstr, "/admin");
- strcat(princstr, "@");
- strcat(princstr, def_realm);
freeprinc++;
} else if ((pw = getpwuid(getuid()))) {
- princstr = (char *) malloc(strlen(pw->pw_name) + 7 /* "/admin@" */
- + strlen(def_realm) + 1);
- if (princstr == NULL) {
+ if (asprintf(&princstr, "%s/admin@%s", pw->pw_name,
+ def_realm) < 0) {
fprintf(stderr, "%s: out of memory\n", whoami);
exit(1);
}
- strcpy(princstr, pw->pw_name);
- strcat(princstr, "/admin@");
- strcat(princstr, def_realm);
freeprinc++;
} else {
fprintf(stderr, "%s: unable to figure out a principal name\n",
int fd;
static char ok[]=".dump_ok";
- if ((file_ok = (char *)malloc(strlen(file_name) + strlen(ok) + 1))
- == NULL) {
+ if (asprintf(&file_ok, "%s%s", file_name, ok) < 0) {
com_err(progname, ENOMEM,
"while allocating filename for update_ok_file");
exit_status++;
return;
}
- strcpy(file_ok, file_name);
- strcat(file_ok, ok);
if ((fd = open(file_ok, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) {
com_err(progname, errno, "while creating 'ok' file, '%s'",
file_ok);
}
dumpfile = argv[aindex];
- if (!(dbname_tmp = (char *) malloc(strlen(dbname)+
- strlen(dump_tmptrail)+1))) {
+ if (asprintf(&dbname_tmp, "%s%s", dbname, dump_tmptrail) < 0) {
fprintf(stderr, no_name_mem_fmt, progname);
exit_status++;
return;
}
- strcpy(dbname_tmp, dbname);
- strcat(dbname_tmp, dump_tmptrail);
/*
* Initialize the Kerberos context and error tables.
global_params.dbname = koptarg;
global_params.mask |= KADM5_CONFIG_DBNAME;
- db_name_tmp = malloc( strlen(global_params.dbname) + sizeof("dbname="));
- if( db_name_tmp == NULL )
+ if (asprintf(&db_name_tmp, "dbname=%s", global_params.dbname) < 0)
{
com_err(progname, ENOMEM, "while parsing command arguments");
exit(1);
}
- strcpy( db_name_tmp, "dbname=");
- strcat( db_name_tmp, global_params.dbname );
-
if (!add_db_arg(db_name_tmp)) {
com_err(progname, ENOMEM, "while parsing command arguments\n");
exit(1);
}
tempdbname = dbname;
} else {
- size_t dbnamelen = strlen(dbname);
- tempdbname = malloc(dbnamelen + 2);
- if (tempdbname == 0) {
+ if (asprintf(&tempdbname, "%s~", dbname) < 0)
com_err(PROGNAME, ENOMEM, "allocating temporary filename");
krb5_free_context(context);
return;
}
- strcpy(tempdbname, dbname);
- tempdbname[dbnamelen] = '~';
- tempdbname[dbnamelen+1] = 0;
(void) krb5_db_destroy(context, tempdbname);
}
char **fullname, krb5_principal * principal)
{
krb5_error_code retval;
- size_t keylen;
- size_t rlen = strlen(realm);
char *fname;
if (!keyname)
keyname = KRB5_KDB_M_NAME; /* XXX external? */
- keylen = strlen(keyname);
-
- fname = malloc(keylen + rlen + strlen(REALM_SEP_STRING) + 1);
- if (!fname)
+ if (asprintf(&fname, "%s%s%s", keyname, REALM_SEP_STRING, realm) < 0)
return ENOMEM;
- strcpy(fname, keyname);
- strcat(fname, REALM_SEP_STRING);
- strcat(fname, realm);
-
if ((retval = krb5_parse_name(context, fname, principal)))
return retval;
if (fullname)
GETDIR;
if (fn && *fn) {
- if (!(d->fn = malloc(strlen(*fn) + dirlen + 1)))
+ if (asprintf(&d->fn, "%s%s%s", dir, PATH_SEPARATOR, *fn) < 0)
return KRB5_RC_IO_MALLOC;
- (void) strcpy(d->fn, dir);
- (void) strcat(d->fn, PATH_SEPARATOR);
- (void) strcat(d->fn, *fn);
unlink(d->fn);
d->fd = THREEPARAMOPEN(d->fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL |
O_BINARY, 0600);
if (!(d->fn = strdup(full_pathname)))
return KRB5_RC_IO_MALLOC;
} else {
- if (!(d->fn = malloc(strlen(fn) + dirlen + 1)))
+ if (asprintf(&d->fn, "%s%s%s", dir, PATH_SEPARATOR, fn) < 0)
return KRB5_RC_IO_MALLOC;
- (void) strcpy(d->fn, dir);
- (void) strcat(d->fn, PATH_SEPARATOR);
- (void) strcat(d->fn, fn);
}
#ifdef NO_USERID
if (sfx == NULL)
return ((char *) NULL);
- dbsuffix = malloc(strlen(db_name) + strlen(sfx) + 1);
- if (!dbsuffix)
+ if (asprintf(&dbsuffix, "%s%s", db_name, sfx) < 0)
return (0);
- (void) strcpy(dbsuffix, db_name);
- (void) strcat(dbsuffix, sfx);
return dbsuffix;
}
data_fn);
exit(1);
}
- if ((data_ok_fn = (char *) malloc(strlen(data_fn)+strlen(ok)+1))
- == NULL) {
+ if (asprintf(&data_ok_fn, "%s%s", data_fn, ok) < 0) {
com_err(progname, ENOMEM, "while trying to malloc data_ok_fn");
exit(1);
}
- strcpy(data_ok_fn, data_fn);
- strcat(data_ok_fn, ok);
if (stat(data_ok_fn, &stbuf_ok)) {
com_err(progname, errno, "while trying to stat %s",
data_ok_fn);
int fd;
static char last_prop[]=".last_prop";
- if ((file_last_prop = (char *)malloc(strlen(file_name) +
- strlen(hostname) + 1 +
- strlen(last_prop) + 1)) == NULL) {
+ if (asprintf(&file_last_prop, "%s.%s%s", file_name, hostname,
+ last_prop) < 0) {
com_err(progname, ENOMEM,
"while allocating filename for update_last_prop_file");
return;
}
- strcpy(file_last_prop, file_name);
- strcat(file_last_prop, ".");
- strcat(file_last_prop, hostname);
- strcat(file_last_prop, last_prop);
if ((fd = THREEPARAMOPEN(file_last_prop, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) {
com_err(progname, errno,
"while creating 'last_prop' file, '%s'",
/*
* Construct the name of the temporary file.
*/
- if ((temp_file_name = (char *) malloc(strlen(file) +
- strlen(tmp) + 1)) == NULL) {
+ if (asprintf(&temp_file_name, "%s%s", file, tmp) < 0) {
com_err(progname, ENOMEM,
"while allocating filename for temp file");
exit(1);
}
- strcpy(temp_file_name, file);
- strcat(temp_file_name, tmp);
retval = kadm5_get_config_params(kpropd_context, 1, ¶ms, ¶ms);
if (retval) {
#include "autoconf.h"
#include "krb5.h"
#include "gssapi/gssapi.h"
+#include "k5-platform.h"
#define HAVE_DLOPEN 1
static int verbose = 1;
{
void *p;
char *namebuf;
- size_t sz;
+ int r;
if (verbose)
printf("from line %d: do_open(%s)...%*s", line, libname,
HORIZ-strlen(libname), "");
- sz = strlen(SHLIB_SUFFIX) + strlen(libname) + 4;
#ifdef _AIX
- sz += strlen(rev) + 8;
+ r = asprintf(&namebuf, "lib%s%s", libname, SHLIB_SUFFIX);
+#else
+ r = asprintf(&namebuf, "lib%s%s(shr.o.%s)", libname, SHLIB_SUFFIX, rev);
#endif
- namebuf = malloc(sz);
- if (namebuf == 0) {
- perror("malloc");
+ if (r < 0) {
+ perror("asprintf");
exit(1);
}
- strcpy(namebuf, "lib");
- strcat(namebuf, libname);
- strcat(namebuf, SHLIB_SUFFIX);
-#ifdef _AIX
- strcat(namebuf, "(shr.o.");
- strcat(namebuf, rev);
- strcat(namebuf, ")");
-#endif
#ifndef RTLD_MEMBER
#define RTLD_MEMBER 0
char const *string;
{
char *rv;
- rv = malloc(strlen(string)+3);
- strcpy(rv, "\"");
- strcat(rv, string);
- strcat(rv, "\"");
+ asprintf(&rv, "\"%s\"", string);
return(rv);
}
#include <errno.h>
+#include "k5-platform.h"
+
#ifndef SYS_ERRLIST_DECLARED
extern char const * const sys_errlist[];
extern const int sys_nerr;
prf_file_t prf;
errcode_t retval;
char *home_env = 0;
- unsigned int len;
prf_data_t data;
char *expanded_filename;
memset(prf, 0, sizeof(struct _prf_file_t));
prf->magic = PROF_MAGIC_FILE;
- len = strlen(filespec)+1;
if (filespec[0] == '~' && filespec[1] == '/') {
home_env = getenv("HOME");
#ifdef HAVE_PWD_H
home_env = pw->pw_dir;
}
#endif
- if (home_env)
- len += strlen(home_env);
}
- expanded_filename = malloc(len);
+ if (home_env) {
+ if (asprintf(&expanded_filename, "%s%s", home_env,
+ filespec + 1) < 0)
+ expanded_filename = 0;
+ } else
+ expanded_filename = strdup(filespec);
if (expanded_filename == 0) {
free(prf);
return ENOMEM;
}
- if (home_env) {
- strcpy(expanded_filename, home_env);
- strcat(expanded_filename, filespec+1);
- } else
- memcpy(expanded_filename, filespec, len);
retval = k5_mutex_lock(&g_shared_trees_mutex);
if (retval) {
char const *cmds;
int options;
{
- int size;
- char *string, *var_name, numbuf[16];
+ char *string, *var_name;
var_name = generate_cmds_string(cmds);
generate_function_definition(func_name);
- size = 6; /* " { " */
- size += strlen(var_name)+8; /* "quux, " */
- size += strlen(func_name)+8; /* "foo, " */
- size += strlen(info_string)+8; /* "\"Info!\", " */
- sprintf(numbuf, "%d", options);
- size += strlen(numbuf)+5; /* " }," + NL + NUL */
- string = malloc(size);
- strcpy(string, " { ");
- strcat(string, var_name);
- strcat(string, ",\n ");
- strcat(string, func_name);
- strcat(string, ",\n ");
- strcat(string, info_string);
- strcat(string, ",\n ");
- strcat(string, numbuf);
- strcat(string, " },\n");
+ asprintf(&string, " { %s,\n %s,\n %s,\n %d },\n",
+ var_name, func_name, info_string, options);
return(string);
}
register char *a, *b, *c;
{
char *result;
- int size_a = strlen(a);
- int size_b = strlen(b);
- int size_c = strlen(c);
- result = malloc((size_a + size_b + size_c + 2)*sizeof(char));
- strcpy(result, a);
- strcpy(&result[size_a], c);
- strcpy(&result[size_a+size_c], b);
+ asprintf(&result, "%s%s%s", a, c, b);
return(result);
}
register char *string;
{
register char *result;
- int len;
- len = strlen(string)+1;
- result = malloc(len+2);
- result[0] = '"';
- strncpy(&result[1], string, len-1);
- result[len] = '"';
- result[len+1] = '\0';
+
+ asprintf(&result, "\"%s\"", string);
return(result);
}