p used before making sure it is not NULL in kernel/auditsc.c
p used before making sure it is not NULL in kernel/auditsc.c
here we should make sure the p is not NULL then use it.
Signed-off-by Zhenwen Xu <[email protected]>
--- kernel/auditsc.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/auditsc.c +3 -2
@@ -341,13 +341,14 @@ static int put_tree_ref(struct audit_context *ctx, struct audit_chunk *chunk) {struct audit_tree_refs *p = ctx->trees;int left = ctx->tree_count; + +if (!p) +return 0 ;if (likely (left)) { p->c[--left] = chunk; ctx->tree_count = left;return 1 ; } -if (!p) -return 0 ; p = p->next;if (p) { p->c[30 ] = chunk;
Signature · 5 lines
1.5.6.5 -- -------------------------------- http://zhwen.org - Open and Free
Quoted 3 lines · Zhenwen Xu
p used before making sure it is not NULL in
kernel/auditsc.chere we should make sure the p is not NULL then use it.
NAK. ->tree_count can become non-zero only after we had set ->trees non-NULL. It's "how much free slots is left in current->trees". If it's zero, we might have an empty chain (->trees is NULL, we bugger off and caller tries to allocate) *or* we might be at the end of the chain (->trees->next is NULL, same as previous) *or* we have more allocated blocks in the chain, so we move to the next block and store in there.
As a general note,
if (foo) {
...
dereference p;
...
} else if (p) {
...
dereference p;
...
}is a perfectly sane code, if foo is true only when p != NULL.