From ae423f53214830de1367627180031283de998746 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 20 Oct 2008 21:14:47 +0000 Subject: Use asprintf instead of malloc/strcpy/strcat in many places ticket: 6200 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20901 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/kcmd.c | 5 +---- src/appl/bsd/krlogind.c | 8 ++------ src/appl/gssftp/ftp/glob.c | 13 +++++-------- 3 files changed, 8 insertions(+), 18 deletions(-) (limited to 'src/appl') diff --git a/src/appl/bsd/kcmd.c b/src/appl/bsd/kcmd.c index 604bcaf20..7d22d5905 100644 --- a/src/appl/bsd/kcmd.c +++ b/src/appl/bsd/kcmd.c @@ -424,13 +424,10 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, 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); diff --git a/src/appl/bsd/krlogind.c b/src/appl/bsd/krlogind.c index cd362a4aa..2fe4c0410 100644 --- a/src/appl/bsd/krlogind.c +++ b/src/appl/bsd/krlogind.c @@ -1478,16 +1478,12 @@ recvauth(valid_checksum) 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, diff --git a/src/appl/gssftp/ftp/glob.c b/src/appl/gssftp/ftp/glob.c index 272e50305..6134798ef 100644 --- a/src/appl/gssftp/ftp/glob.c +++ b/src/appl/gssftp/ftp/glob.c @@ -57,6 +57,8 @@ static char sccsid[] = "@(#)glob.c 5.9 (Berkeley) 2/25/91"; #include #endif +#include + #include "ftp_var.h" #ifdef ARG_MAX @@ -258,10 +260,7 @@ matchdir(pattern) 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) @@ -732,12 +731,10 @@ char * 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); } -- cgit