Skip to content

Commit

Permalink
Fix util_is_printable_string
Browse files Browse the repository at this point in the history
The method used did not account for multi-part strings.

Signed-off-by: Pantelis Antoniou <[email protected]>
Acked-by: David Gibson <[email protected]>
  • Loading branch information
pantoniou authored and Jon Loeliger committed Jan 6, 2013
1 parent 94a4799 commit 1c1efd6
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ char *join_path(const char *path, const char *name)
int util_is_printable_string(const void *data, int len)
{
const char *s = data;
const char *ss;
const char *ss, *se;

/* zero length is not */
if (len == 0)
Expand All @@ -82,13 +82,19 @@ int util_is_printable_string(const void *data, int len)
if (s[len - 1] != '\0')
return 0;

ss = s;
while (*s && isprint(*s))
s++;
se = s + len;

/* not zero, or not done yet */
if (*s != '\0' || (s + 1 - ss) < len)
return 0;
while (s < se) {
ss = s;
while (s < se && *s && isprint(*s))
s++;

/* not zero, or not done yet */
if (*s != '\0' || s == ss)
return 0;

s++;
}

return 1;
}
Expand Down

0 comments on commit 1c1efd6

Please sign in to comment.