Check return value from asprintf instead of string != NULL since it

undefined behavior on Linux. From Björn Sandell


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16215 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2005-10-22 12:49:00 +00:00
parent 911c099056
commit f74a40ff85
4 changed files with 15 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998 - 2003 Kungliga Tekniska H<>gskolan
* Copyright (c) 1998 - 2005 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -306,7 +306,7 @@ import_name(const char *kname, const char *host, gss_name_t *target_name)
gss_buffer_desc name;
name.length = asprintf((char**)&name.value, "%s@%s", kname, host);
if (name.value == NULL) {
if (name.length == -1) {
printf("Out of memory\n");
return AUTH_ERROR;
}

View File

@@ -310,8 +310,11 @@ sec_vfprintf2(FILE *f, const char *fmt, va_list ap)
if(data_prot == prot_clear)
return vfprintf(f, fmt, ap);
else {
vasprintf(&buf, fmt, ap);
ret = buffer_write(&out_buffer, buf, strlen(buf));
int len;
len = vasprintf(&buf, fmt, ap);
if (len == -1)
return len;
ret = buffer_write(&out_buffer, buf, len);
free(buf);
return ret;
}
@@ -379,7 +382,10 @@ sec_vfprintf(FILE *f, const char *fmt, va_list ap)
if(!sec_complete)
return vfprintf(f, fmt, ap);
vasprintf(&buf, fmt, ap);
if (vasprintf(&buf, fmt, ap) == -1) {
printf("Failed to allocate command.\n");
return -1;
}
len = (*mech->encode)(app_data, buf, strlen(buf), command_prot, &enc);
free(buf);
if(len < 0) {

View File

@@ -1023,9 +1023,10 @@ retrieve(const char *cmd, char *name)
*tail = c;
if (p->rev_cmd != NULL) {
char *ext;
int ret;
asprintf(&ext, "%s%s", name, p->ext);
if (ext != NULL) {
ret = asprintf(&ext, "%s%s", name, p->ext);
if (ret != -1) {
if (access(ext, R_OK) == 0) {
snprintf (line, sizeof(line),
p->rev_cmd, ext);

View File

@@ -105,8 +105,7 @@ gss_userok(void *app_data, char *username)
chown (ticketfile, kpw->pw_uid, kpw->pw_gid);
asprintf(&k5ccname, "FILE:%s", ticketfile);
if (k5ccname) {
if (asprintf(&k5ccname, "FILE:%s", ticketfile) != -1) {
esetenv ("KRB5CCNAME", k5ccname, 1);
}
afslog(NULL, 1);