blob: f53341d3fc2fcf0d79cd08016dc2bd084e7ea543 [file] [log] [blame]
Patrick Williams8e7b46e2023-05-01 14:19:06 -05001From e5905c4b84d4fb90aefcd96ee618411ebfac663d Mon Sep 17 00:00:00 2001
2From: tomspiderlabs <128755403+tomspiderlabs@users.noreply.github.com>
3Date: Thu, 23 Mar 2023 23:39:38 +0000
4Subject: [PATCH] Added control character check
5
6Added control character check, returning -1 (to "err") if control characters are present.
7
8CVE: CVE-2023-29383
9Upstream-Status: Backport
10
11Reference to upstream:
12https://github.com/shadow-maint/shadow/commit/e5905c4b84d4fb90aefcd96ee618411ebfac663d
13
14Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
15---
16 lib/fields.c | 11 +++++++----
17 1 file changed, 7 insertions(+), 4 deletions(-)
18
19diff --git a/lib/fields.c b/lib/fields.c
20index 640be931..fb51b582 100644
21--- a/lib/fields.c
22+++ b/lib/fields.c
23@@ -21,9 +21,9 @@
24 *
25 * The supplied field is scanned for non-printable and other illegal
26 * characters.
27- * + -1 is returned if an illegal character is present.
28- * + 1 is returned if no illegal characters are present, but the field
29- * contains a non-printable character.
30+ * + -1 is returned if an illegal or control character is present.
31+ * + 1 is returned if no illegal or control characters are present,
32+ * but the field contains a non-printable character.
33 * + 0 is returned otherwise.
34 */
35 int valid_field (const char *field, const char *illegal)
36@@ -45,10 +45,13 @@ int valid_field (const char *field, const char *illegal)
37 }
38
39 if (0 == err) {
40- /* Search if there are some non-printable characters */
41+ /* Search if there are non-printable or control characters */
42 for (cp = field; '\0' != *cp; cp++) {
43 if (!isprint (*cp)) {
44 err = 1;
45+ }
46+ if (!iscntrl (*cp)) {
47+ err = -1;
48 break;
49 }
50 }
51--
522.34.1
53