Skip to content

Commit 00e0590

Browse files
Colin Ian Kingjrjohansen
authored andcommitted
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: f1bd904 ("apparmor: add the base fns() for domain labels") Signed-off-by: Colin Ian King <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent 136db99 commit 00e0590

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

security/apparmor/label.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,11 +1462,13 @@ static inline bool use_label_hname(struct aa_ns *ns, struct aa_label *label,
14621462
/* helper macro for snprint routines */
14631463
#define update_for_len(total, len, size, str) \
14641464
do { \
1465+
size_t ulen = len; \
1466+
\
14651467
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; \
14701472
} while (0)
14711473

14721474
/**
@@ -1601,7 +1603,7 @@ int aa_label_snxprint(char *str, size_t size, struct aa_ns *ns,
16011603
struct aa_ns *prev_ns = NULL;
16021604
struct label_it i;
16031605
int count = 0, total = 0;
1604-
size_t len;
1606+
ssize_t len;
16051607

16061608
AA_BUG(!str && size != 0);
16071609
AA_BUG(!label);

0 commit comments

Comments
 (0)