Skip to content

Commit e5905c4

Browse files
tomspiderlabshallyn
authored andcommitted
Added control character check
Added control character check, returning -1 (to "err") if control characters are present.
1 parent bd2d007 commit e5905c4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/fields.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*
2222
* The supplied field is scanned for non-printable and other illegal
2323
* characters.
24-
* + -1 is returned if an illegal character is present.
25-
* + 1 is returned if no illegal characters are present, but the field
26-
* contains a non-printable character.
24+
* + -1 is returned if an illegal or control character is present.
25+
* + 1 is returned if no illegal or control characters are present,
26+
* but the field contains a non-printable character.
2727
* + 0 is returned otherwise.
2828
*/
2929
int valid_field (const char *field, const char *illegal)
@@ -45,10 +45,13 @@ int valid_field (const char *field, const char *illegal)
4545
}
4646

4747
if (0 == err) {
48-
/* Search if there are some non-printable characters */
48+
/* Search if there are non-printable or control characters */
4949
for (cp = field; '\0' != *cp; cp++) {
5050
if (!isprint (*cp)) {
5151
err = 1;
52+
}
53+
if (!iscntrl (*cp)) {
54+
err = -1;
5255
break;
5356
}
5457
}

0 commit comments

Comments
 (0)