single_domain: Invalid memory access for empty string input

We noticed a small buglet in ares_search() when it gets an empty string
as input -- the single_domain() utility function in ares_search.c
accesses invalid memory (before the start of the string).
pull/12/head
David Drysdale 12 years ago committed by Daniel Stenberg
parent c8ec633bf5
commit 4aa1fc4163
  1. 2
      ares_search.c

@ -239,7 +239,7 @@ static int single_domain(ares_channel channel, const char *name, char **s)
/* If the name contains a trailing dot, then the single query is the name
* sans the trailing dot.
*/
if (name[len - 1] == '.')
if ((len > 0) && (name[len - 1] == '.'))
{
*s = strdup(name);
return (*s) ? ARES_SUCCESS : ARES_ENOMEM;

Loading…
Cancel
Save