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@16224 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2005-10-22 17:17:44 +00:00
parent af8272f96c
commit d448f74010
2 changed files with 9 additions and 6 deletions

View File

@@ -1582,6 +1582,7 @@ env_init(void)
|| strncmp((char *)ep->value, "unix:", 5) == 0)) { || strncmp((char *)ep->value, "unix:", 5) == 0)) {
char hbuf[256+1]; char hbuf[256+1];
char *cp2 = strchr((char *)ep->value, ':'); char *cp2 = strchr((char *)ep->value, ':');
int error;
/* XXX - should be k_gethostname? */ /* XXX - should be k_gethostname? */
gethostname(hbuf, 256); gethostname(hbuf, 256);
@@ -1590,7 +1591,6 @@ env_init(void)
/* If this is not the full name, try to get it via DNS */ /* If this is not the full name, try to get it via DNS */
if (strchr(hbuf, '.') == 0) { if (strchr(hbuf, '.') == 0) {
struct addrinfo hints, *ai, *a; struct addrinfo hints, *ai, *a;
int error;
memset (&hints, 0, sizeof(hints)); memset (&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME; hints.ai_flags = AI_CANONNAME;
@@ -1608,9 +1608,11 @@ env_init(void)
} }
} }
asprintf (&cp, "%s%s", hbuf, cp2); error = asprintf (&cp, "%s%s", hbuf, cp2);
free (ep->value); if (error != -1) {
ep->value = (unsigned char *)cp; free (ep->value);
ep->value = (unsigned char *)cp;
}
} }
/* /*
* If USER is not defined, but LOGNAME is, then add * If USER is not defined, but LOGNAME is, then add

View File

@@ -244,9 +244,10 @@ init_words (int argc, char **argv)
appres.file = argv[i]; appres.file = argv[i];
i++; i++;
} else { } else {
asprintf (&appres.file, int ret;
ret = asprintf (&appres.file,
"%s/.msgfile", getenv("HOME")); "%s/.msgfile", getenv("HOME"));
if (appres.file == NULL) if (ret == -1)
errx (1, "cannot allocate memory for message"); errx (1, "cannot allocate memory for message");
} }
} else if(strcmp(argv[i], "--version") == 0) { } else if(strcmp(argv[i], "--version") == 0) {