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. 20
      util.c

20
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,13 +82,19 @@ int util_is_printable_string(const void *data, int len)
if (s[len - 1] != '\0') if (s[len - 1] != '\0')
return 0; return 0;


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


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

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

s++;
}


return 1; return 1;
} }

Loading…
Cancel
Save