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).
This commit is contained in:
David Drysdale 2013-11-12 11:03:15 -08:00 committed by Daniel Stenberg
parent c8ec633bf5
commit 4aa1fc4163
1 changed files with 1 additions and 1 deletions

View File

@ -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;