fix two related bugs in context_{new,free}
PATCH 1/1 fix two related bugs in context_{new,free}
This patch fixes two bugs found by Coverity in context.c.
1. When the malloc() for n fails, but that for result succeeds, then result->ptr is dereferenced and used in context_free(); but it was never initialized either to 0 or to n.
2. When the malloc for n succeeds but for result fails, then n is never freed.
context.c +4 -1
@@ -25,10 +25,13 @@ context_new(const char *str)context_t result = (context_t )malloc (sizeof (context_s_t));const char *p,*tok; +if (result) + result->ptr = n; +else +free (n);if ( n ==0 || result ==0 ) { goto err; } n->current_str = n->component[0 ] = n->component[1 ] = n->component[2 ] = n->component[3 ] =0 ; - result->ptr = n;for ( i = count =0 , p = str; *p; p++ ) {switch ( *p ) {case ':' : count++;break ;
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.