Skip to content

Commit 7f9e006

Browse files
Ar-maan05millert
authored andcommitted
parse_ldif: keep the full length when joining folded lines
When a folded LDIF line was appended to the saved portion, len was left as the length of the continuation alone. A second continuation was then saved with that short length and copied over the middle of the attribute, so a value folded over three or more lines was corrupted, e.g. "sudoCommand: /usr/bin/sys", " temctl rest", " art httpd" became "sudoCommandart httpd" and was rejected as an invalid LDIF attribute. Add the saved length to len after the append, and add a cvtsudoers regression test.
1 parent 0e2c376 commit 7f9e006

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎MANIFEST‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ plugins/sudoers/regress/cvtsudoers/test40.out.ok
866866
plugins/sudoers/regress/cvtsudoers/test40.sh
867867
plugins/sudoers/regress/cvtsudoers/test41.out.ok
868868
plugins/sudoers/regress/cvtsudoers/test41.sh
869+
plugins/sudoers/regress/cvtsudoers/test42.out.ok
870+
plugins/sudoers/regress/cvtsudoers/test42.sh
869871
plugins/sudoers/regress/cvtsudoers/test5.out.ok
870872
plugins/sudoers/regress/cvtsudoers/test5.sh
871873
plugins/sudoers/regress/cvtsudoers/test6.out.ok

‎plugins/sudoers/parse_ldif.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ sudoers_parse_ldif(struct sudoers_parse_tree *parse_tree,
654654
memcpy(tmp + savedlen, line, (size_t)len + 1);
655655
free(line);
656656
line = tmp;
657+
len += (ssize_t)savedlen;
657658
savedline = NULL;
658659
}
659660

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# sudoRole millert
2+
millert ALL = /usr/bin/systemctl restart httpd, /usr/bin/ls
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
#
3+
# Test an LDIF attribute folded over more than two lines.
4+
#
5+
6+
: ${CVTSUDOERS=cvtsudoers}
7+
8+
$CVTSUDOERS -c "" -i ldif -b "ou=SUDOers,dc=sudo,dc=ws" -f sudoers <<EOF
9+
dn: cn=millert,ou=SUDOers,dc=sudo,dc=ws
10+
objectClass: top
11+
objectClass: sudoRole
12+
cn: millert
13+
sudoUser: millert
14+
sudoHost: ALL
15+
sudoCommand: /usr/bin/sys
16+
temctl rest
17+
art httpd
18+
sudoCommand: /usr/bin/ls
19+
20+
EOF

0 commit comments

Comments
 (0)