From 2f15ffd6b5beef9abd501c594bc3cb38c2683f77 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Fri, 2 Jul 2010 04:55:28 +0000 Subject: NULL dereference fixes in code base after running with 'clang' * 212 logical (NULL deref/divide by zero) errors reduced to 28 (27 of them in contrib/ and lex part of codebase, 1 is invalid) * 11 API errors reduced to 0 Signed-off-by: Amar Tumballi Signed-off-by: Anand V. Avati BUG: 966 (NULL check for avoiding NULL dereferencing of pointers..) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=966 --- libglusterfs/src/common-utils.c | 3 ++- libglusterfs/src/dict.c | 5 +++-- libglusterfs/src/event.c | 2 +- libglusterfs/src/graph.l | 6 ++++-- libglusterfs/src/graph.y | 2 +- libglusterfs/src/stack.h | 9 ++++++++- 6 files changed, 19 insertions(+), 8 deletions(-) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 694a9040c95..1be1f81268b 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -150,7 +150,8 @@ gf_resolve_ip6 (const char *hostname, *addr_info = cache->next; } - cache->next = cache->next->ai_next; + if (cache->next) + cache->next = cache->next->ai_next; if (cache->next) { ret = getnameinfo((struct sockaddr *)cache->next->ai_addr, cache->next->ai_addrlen, diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 7d560bdac71..ca6275f26b8 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -581,9 +581,10 @@ dict_unserialize_old (char *buf, int32_t size, dict_t **fill) int32_t ret = 0; int32_t cnt = 0; - if (!buf || fill == NULL || !*fill) { + if (!buf || !fill || !(*fill)) { gf_log ("dict", GF_LOG_ERROR, - "@buf=%p @fill=%p @*fill=%p", buf, fill, *fill); + "@buf=%p @fill=%p @*fill=%p", + buf, fill, (fill) ? (*fill) : NULL); return NULL; } diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c index 819357d437a..7ac891fa122 100644 --- a/libglusterfs/src/event.c +++ b/libglusterfs/src/event.c @@ -867,7 +867,7 @@ event_dispatch_epoll (struct event_pool *event_pool) size = ret; for (i = 0; i < size; i++) { - if (!events[i].events) + if (!events || !events[i].events) continue; ret = event_dispatch_epoll_handler (event_pool, diff --git a/libglusterfs/src/graph.l b/libglusterfs/src/graph.l index 8d9d2dc3611..f7a02e48107 100644 --- a/libglusterfs/src/graph.l +++ b/libglusterfs/src/graph.l @@ -45,12 +45,14 @@ void append_string(const char *str, int size) } else { text = GF_REALLOC (text, new_size); } - if (!text) + if (!text) { gf_log ("parser", GF_LOG_ERROR, "out of memory"); + return; + } text_asize = new_size; } - memcpy(text + text_size, str, size); + memcpy(text + text_size, str, size); text_size += size; text[text_size] = 0; } diff --git a/libglusterfs/src/graph.y b/libglusterfs/src/graph.y index 4ac07660f95..14afaae6475 100644 --- a/libglusterfs/src/graph.y +++ b/libglusterfs/src/graph.y @@ -382,7 +382,7 @@ yyerror (const char *str) extern char *yytext; extern int yylineno; - if (curr && curr->name) { + if (curr && curr->name && yytext) { if (!strcmp (yytext, "volume")) { gf_log ("parser", GF_LOG_ERROR, "'end-volume' not defined for volume '%s'", diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h index ac69e389f22..1ce46ccdc89 100644 --- a/libglusterfs/src/stack.h +++ b/libglusterfs/src/stack.h @@ -253,7 +253,10 @@ STACK_DESTROY (call_stack_t *stack) ret_fn_t fn = NULL; \ call_frame_t *_parent = NULL; \ xlator_t *old_THIS = NULL; \ - \ + if (!frame) { \ + gf_log ("stack", GF_LOG_CRITICAL, "!frame"); \ + break; \ + } \ fn = frame->ret; \ _parent = frame->parent; \ _parent->ref_count--; \ @@ -277,6 +280,10 @@ STACK_DESTROY (call_stack_t *stack) call_frame_t *_parent = NULL; \ xlator_t *old_THIS = NULL; \ \ + if (!frame) { \ + gf_log ("stack", GF_LOG_CRITICAL, "!frame"); \ + break; \ + } \ fn = (fop_##op##_cbk_t )frame->ret; \ _parent = frame->parent; \ _parent->ref_count--; \ -- cgit