Browse Source

Fix util_is_printable_string

The method used did not account for multi-part strings.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
main
Pantelis Antoniou 12 years ago committed by Jon Loeliger
parent
commit
1c1efd6954
  1. 12
      util.c

12
util.c

@ -72,7 +72,7 @@ char *join_path(const char *path, const char *name)
int util_is_printable_string(const void *data, int len) int util_is_printable_string(const void *data, int len)
{ {
const char *s = data; const char *s = data;
const char *ss; const char *ss, *se;


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


se = s + len;

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


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


s++;
}

return 1; return 1;
} }



Loading…
Cancel
Save