Skip to content

Commit

Permalink
nfq: fix potential NULL dereference
Browse files Browse the repository at this point in the history
 Added assert statement for NFQGetQueue so that
 it is not possible to return NULL.
 Also deleted useless check of returned value of
 NFQGetQueue() in NFQInitThread()

Found by Security Code with Svace static analyzer
Signed-off-by: Maxim Korotkov <[email protected]>
  • Loading branch information
Maxim Korotkov authored and ProjectMutilation committed Jul 5, 2023
1 parent 416a780 commit e320204
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/source-nfq.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,6 @@ static TmEcode NFQInitThread(NFQThreadVars *t, uint32_t queue_maxlen)
struct timeval tv;
int opt;
NFQQueueVars *q = NFQGetQueue(t->nfq_index);
if (q == NULL) {
SCLogError("no queue for given index");
return TM_ECODE_FAILED;
}
SCLogDebug("opening library handle");
q->h = nfq_open();
if (q->h == NULL) {
Expand Down Expand Up @@ -915,13 +911,10 @@ int NFQParseAndRegisterQueues(const char *queues)
* \param number idx of the queue in our array
*
* \retval ptr pointer to the NFQThreadVars at index
* \retval NULL on error
*/
void *NFQGetQueue(int number)
{
if (unlikely(number < 0 || number >= receive_queue_num || g_nfq_q == NULL))
return NULL;

BUG_ON(number < 0 || number >= receive_queue_num || g_nfq_q == NULL);
return (void *)&g_nfq_q[number];
}

Expand Down

0 comments on commit e320204

Please sign in to comment.