From d448f740102271f74bbf3950c129881f75501d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Sat, 22 Oct 2005 17:17:44 +0000 Subject: [PATCH] =?UTF-8?q?Check=20return=20value=20from=20asprintf=20inst?= =?UTF-8?q?ead=20of=20string=20!=3D=20NULL=20since=20it=20undefined=20beha?= =?UTF-8?q?vior=20on=20Linux.=20From=20Bj=C3=B6rn=20Sandell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16224 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/telnet/telnet/commands.c | 10 ++++++---- appl/xnlock/xnlock.c | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/appl/telnet/telnet/commands.c b/appl/telnet/telnet/commands.c index 980abcd5c..1f8583481 100644 --- a/appl/telnet/telnet/commands.c +++ b/appl/telnet/telnet/commands.c @@ -1582,6 +1582,7 @@ env_init(void) || strncmp((char *)ep->value, "unix:", 5) == 0)) { char hbuf[256+1]; char *cp2 = strchr((char *)ep->value, ':'); + int error; /* XXX - should be k_gethostname? */ gethostname(hbuf, 256); @@ -1590,7 +1591,6 @@ env_init(void) /* If this is not the full name, try to get it via DNS */ if (strchr(hbuf, '.') == 0) { struct addrinfo hints, *ai, *a; - int error; memset (&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; @@ -1608,9 +1608,11 @@ env_init(void) } } - asprintf (&cp, "%s%s", hbuf, cp2); - free (ep->value); - ep->value = (unsigned char *)cp; + error = asprintf (&cp, "%s%s", hbuf, cp2); + if (error != -1) { + free (ep->value); + ep->value = (unsigned char *)cp; + } } /* * If USER is not defined, but LOGNAME is, then add diff --git a/appl/xnlock/xnlock.c b/appl/xnlock/xnlock.c index 3ba32abdd..b92f439f9 100644 --- a/appl/xnlock/xnlock.c +++ b/appl/xnlock/xnlock.c @@ -244,9 +244,10 @@ init_words (int argc, char **argv) appres.file = argv[i]; i++; } else { - asprintf (&appres.file, + int ret; + ret = asprintf (&appres.file, "%s/.msgfile", getenv("HOME")); - if (appres.file == NULL) + if (ret == -1) errx (1, "cannot allocate memory for message"); } } else if(strcmp(argv[i], "--version") == 0) {