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>
This commit is contained in:
parent
94a4799b20
commit
1c1efd6954
1 changed files with 13 additions and 7 deletions
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)
|
||||
{
|
||||
const char *s = data;
|
||||
const char *ss;
|
||||
const char *ss, *se;
|
||||
|
||||
/* zero length is not */
|
||||
if (len == 0)
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue