* p used before making sure it is not NULL in kernel/auditsc.c
@ 2009-05-22 2:22 Zhenwen Xu
2009-05-22 4:07 ` Al Viro
0 siblings, 1 reply; 2+ messages in thread
From: Zhenwen Xu @ 2009-05-22 2:22 UTC (permalink / raw)
To: linux-kernel; +Cc: viro, eparis
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 <helight.xu@gmail.com>
---
kernel/auditsc.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 7d6ac7c..876fdd1 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -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;
--
1.5.6.5
--
--------------------------------
http://zhwen.org - Open and Free
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: p used before making sure it is not NULL in kernel/auditsc.c
2009-05-22 2:22 p used before making sure it is not NULL in kernel/auditsc.c Zhenwen Xu
@ 2009-05-22 4:07 ` Al Viro
0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2009-05-22 4:07 UTC (permalink / raw)
To: Zhenwen Xu; +Cc: linux-kernel, eparis
On Fri, May 22, 2009 at 10:22:41AM +0800, Zhenwen Xu wrote:
> 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.
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-05-22 4:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-22 2:22 p used before making sure it is not NULL in kernel/auditsc.c Zhenwen Xu
2009-05-22 4:07 ` Al Viro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox