aboutsummaryrefslogtreecommitdiff
path: root/lib/hostip.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-05-20 09:41:39 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-05-20 09:41:39 +0000
commit9a6566e7743cb6f95efe7f5ca889e5589fcb1436 (patch)
tree12076184f7834666cba824c29d7782f95a0d0412 /lib/hostip.c
parent4da0428d9edf9c55bdf71121dc29271508dbca44 (diff)
Gisle Vanem's code for not trusting h_aliases to always be non-NULL
Diffstat (limited to 'lib/hostip.c')
-rw-r--r--lib/hostip.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/hostip.c b/lib/hostip.c
index dc38b9f74..c245ab1b7 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -455,18 +455,22 @@ static struct hostent* pack_hostent(char** buf, struct hostent* orig)
copy->h_aliases = (char**)bufptr;
/* Figure out how many aliases there are */
- for (i = 0; orig->h_aliases[i] != NULL; ++i);
+ for (i = 0; orig->h_aliases && orig->h_aliases[i]; ++i);
/* Reserve room for the array */
bufptr += (i + 1) * sizeof(char*);
/* Clone all known aliases */
- for(i = 0; (str = orig->h_aliases[i]); i++) {
- len = strlen(str) + 1;
- strncpy(bufptr, str, len);
- copy->h_aliases[i] = bufptr;
- bufptr += len;
+ if(orig->h_aliases) {
+ for(i = 0; (str = orig->h_aliases[i]); i++) {
+ len = strlen(str) + 1;
+ strncpy(bufptr, str, len);
+ copy->h_aliases[i] = bufptr;
+ bufptr += len;
+ }
}
+ /* if(!orig->h_aliases) i was already set to 0 */
+
/* Terminate the alias list with a NULL */
copy->h_aliases[i] = NULL;