From fae1abf1e8417e1d651caea574b3e3c09f5305de Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Fri, 14 Jan 2000 00:58:02 +0000 Subject: [PATCH] Bugzilla bug #20770: CopyHostent should handle the possibility that h_aliases is null. In that case, we allocate in our copy a one-element array whose only element is a null pointer. --- nsprpub/pr/src/misc/prnetdb.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/nsprpub/pr/src/misc/prnetdb.c b/nsprpub/pr/src/misc/prnetdb.c index 22f9f4f32d6..f3e65ff2460 100644 --- a/nsprpub/pr/src/misc/prnetdb.c +++ b/nsprpub/pr/src/misc/prnetdb.c @@ -245,19 +245,27 @@ static PRStatus CopyHostent( memcpy(to->h_name, from->h_name, len); /* Count the aliases, then allocate storage for the pointers */ - for (na = 1, ap = from->h_aliases; *ap != 0; na++, ap++){;} /* nothing to execute */ + if (!from->h_aliases) { + na = 1; + } else { + for (na = 1, ap = from->h_aliases; *ap != 0; na++, ap++){;} /* nothing to execute */ + } to->h_aliases = (char**)Alloc( na * sizeof(char*), &buf, &bufsize, sizeof(char**)); if (!to->h_aliases) return PR_FAILURE; /* Copy the aliases, one at a time */ - for (na = 0, ap = from->h_aliases; *ap != 0; na++, ap++) { - len = strlen(*ap) + 1; - to->h_aliases[na] = Alloc(len, &buf, &bufsize, 0); - if (!to->h_aliases[na]) return PR_FAILURE; - memcpy(to->h_aliases[na], *ap, len); + if (!from->h_aliases) { + to->h_aliases[0] = 0; + } else { + for (na = 0, ap = from->h_aliases; *ap != 0; na++, ap++) { + len = strlen(*ap) + 1; + to->h_aliases[na] = Alloc(len, &buf, &bufsize, 0); + if (!to->h_aliases[na]) return PR_FAILURE; + memcpy(to->h_aliases[na], *ap, len); + } + to->h_aliases[na] = 0; } - to->h_aliases[na] = 0; /* Count the addresses, then allocate storage for the pointers */ for (na = 1, ap = from->h_addr_list; *ap != 0; na++, ap++){;} /* nothing to execute */