fixes from PVS-Studio #2032

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@ip-gpu

ip-gpu commented Oct 30, 2017

I'm a member of the Pinguem.ru competition on finding errors in open source projects. A bug, found using PVS-Studio. Warnings:

V522 Dereferencing of the null pointer 'pv' might take place. cookie.c 316

fixes from PVS-Studio
V522 Dereferencing of the null pointer 'pv' might take place. cookie.c 316
@bagder

This comment has been minimized.

Show comment
Hide comment
@bagder

bagder Oct 30, 2017

Member

CI failures because it doesn't follow our code style. But more importantly, shouldn't the fix rather be?

--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -307,11 +307,11 @@ static void remove_expired(struct CookieInfo *cookies)
   co = cookies->cookies;
   pv = NULL;
   while(co) {
     nx = co->next;
     if(co->expires && co->expires < now) {
-      if(co == cookies->cookies) {
+      if(!pv) {
         cookies->cookies = co->next;
       }
       else {
         pv->next = co->next;
       }
Member

bagder commented Oct 30, 2017

CI failures because it doesn't follow our code style. But more importantly, shouldn't the fix rather be?

--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -307,11 +307,11 @@ static void remove_expired(struct CookieInfo *cookies)
   co = cookies->cookies;
   pv = NULL;
   while(co) {
     nx = co->next;
     if(co->expires && co->expires < now) {
-      if(co == cookies->cookies) {
+      if(!pv) {
         cookies->cookies = co->next;
       }
       else {
         pv->next = co->next;
       }

bagder added a commit that referenced this pull request Oct 30, 2017

cookie: avoid NULL dereference
... when expiring old cookies.

Reported-by: Pavel Gushchin
Fixes #2032

@bagder bagder closed this in fa394c8 Oct 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment