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.
This commit is contained in:
wtc%netscape.com 2000-01-14 00:58:02 +00:00
Родитель 1d7a5bdd34
Коммит fae1abf1e8
1 изменённых файлов: 15 добавлений и 7 удалений

Просмотреть файл

@ -245,19 +245,27 @@ static PRStatus CopyHostent(
memcpy(to->h_name, from->h_name, len); memcpy(to->h_name, from->h_name, len);
/* Count the aliases, then allocate storage for the pointers */ /* 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( to->h_aliases = (char**)Alloc(
na * sizeof(char*), &buf, &bufsize, sizeof(char**)); na * sizeof(char*), &buf, &bufsize, sizeof(char**));
if (!to->h_aliases) return PR_FAILURE; if (!to->h_aliases) return PR_FAILURE;
/* Copy the aliases, one at a time */ /* Copy the aliases, one at a time */
for (na = 0, ap = from->h_aliases; *ap != 0; na++, ap++) { if (!from->h_aliases) {
len = strlen(*ap) + 1; to->h_aliases[0] = 0;
to->h_aliases[na] = Alloc(len, &buf, &bufsize, 0); } else {
if (!to->h_aliases[na]) return PR_FAILURE; for (na = 0, ap = from->h_aliases; *ap != 0; na++, ap++) {
memcpy(to->h_aliases[na], *ap, len); 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 */ /* Count the addresses, then allocate storage for the pointers */
for (na = 1, ap = from->h_addr_list; *ap != 0; na++, ap++){;} /* nothing to execute */ for (na = 1, ap = from->h_addr_list; *ap != 0; na++, ap++){;} /* nothing to execute */