Commit 00e0590dbaec6f1bcaa36a85467d7e3497ced522
Committed by
John Johansen
1 parent
136db99485
apparmor: fix unsigned len comparison with less than zero
The sanity check in macro update_for_len checks to see if len is less than zero, however, len is a size_t so it can never be less than zero, so this sanity check is a no-op. Fix this by making len a ssize_t so the comparison will work and add ulen that is a size_t copy of len so that the min() macro won't throw warnings about comparing different types. Addresses-Coverity: ("Macro compares unsigned to 0") Fixes: f1bd904175e8 ("apparmor: add the base fns() for domain labels") Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
Showing 1 changed file with 7 additions and 5 deletions Side-by-side Diff
security/apparmor/label.c
... | ... | @@ -1462,11 +1462,13 @@ |
1462 | 1462 | /* helper macro for snprint routines */ |
1463 | 1463 | #define update_for_len(total, len, size, str) \ |
1464 | 1464 | do { \ |
1465 | + size_t ulen = len; \ | |
1466 | + \ | |
1465 | 1467 | AA_BUG(len < 0); \ |
1466 | - total += len; \ | |
1467 | - len = min(len, size); \ | |
1468 | - size -= len; \ | |
1469 | - str += len; \ | |
1468 | + total += ulen; \ | |
1469 | + ulen = min(ulen, size); \ | |
1470 | + size -= ulen; \ | |
1471 | + str += ulen; \ | |
1470 | 1472 | } while (0) |
1471 | 1473 | |
1472 | 1474 | /** |
... | ... | @@ -1601,7 +1603,7 @@ |
1601 | 1603 | struct aa_ns *prev_ns = NULL; |
1602 | 1604 | struct label_it i; |
1603 | 1605 | int count = 0, total = 0; |
1604 | - size_t len; | |
1606 | + ssize_t len; | |
1605 | 1607 | |
1606 | 1608 | AA_BUG(!str && size != 0); |
1607 | 1609 | AA_BUG(!label); |