Commit 29e9a3467c1367549568d7d411d5f30209ae181b
Committed by
Al Viro
1 parent
563a0d1236
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
audit: make audit_compare_dname_path use parent_len helper
Signed-off-by: Eric Paris <eparis@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 1 changed file with 7 additions and 20 deletions Side-by-side Diff
kernel/auditfilter.c
... | ... | @@ -1332,32 +1332,19 @@ |
1332 | 1332 | * return of 0 indicates a match. */ |
1333 | 1333 | int audit_compare_dname_path(const char *dname, const char *path) |
1334 | 1334 | { |
1335 | - int dlen, plen; | |
1335 | + int dlen, pathlen, parentlen; | |
1336 | 1336 | const char *p; |
1337 | 1337 | |
1338 | - if (!dname || !path) | |
1339 | - return 1; | |
1340 | - | |
1341 | 1338 | dlen = strlen(dname); |
1342 | - plen = strlen(path); | |
1343 | - if (plen < dlen) | |
1339 | + pathlen = strlen(path); | |
1340 | + if (pathlen < dlen) | |
1344 | 1341 | return 1; |
1345 | 1342 | |
1346 | - /* disregard trailing slashes */ | |
1347 | - p = path + plen - 1; | |
1348 | - while ((*p == '/') && (p > path)) | |
1349 | - p--; | |
1350 | - | |
1351 | - /* find last path component */ | |
1352 | - p = p - dlen + 1; | |
1353 | - if (p < path) | |
1343 | + parentlen = parent_len(path); | |
1344 | + if (pathlen - parentlen != dlen) | |
1354 | 1345 | return 1; |
1355 | - else if (p > path) { | |
1356 | - if (*--p != '/') | |
1357 | - return 1; | |
1358 | - else | |
1359 | - p++; | |
1360 | - } | |
1346 | + | |
1347 | + p = path + parentlen; | |
1361 | 1348 | |
1362 | 1349 | return strncmp(p, dname, dlen); |
1363 | 1350 | } |