miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Minor issues from cppcheck

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpd Bugs
View previous topic :: View next topic  
Author Message
fox88



Joined: 05 Feb 2015
Posts: 9

PostPosted: Sat Mar 05, 2016 8:23 am    Post subject: Minor issues from cppcheck Reply with quote

In file miniupnpcommands.c both lines 583 and 584 are flagged with the messages:
Either the condition 'p&&intClient' is redundant or there is possible null pointer dereference: intClient.

The lines in question are:
Code:
   intClient[0] = '\0';
   intPort[0] = '\0';


The reason is that below at line 619 both pointers are checked for null
Code:

   if(p && intClient)
   {
      strncpy(intClient, p, 16);
      intClient[15] = '\0';
      r = 0;
   }
   p = GetValueFromNameValueList(&pdata, "NewInternalPort");
   if(p && intPort)
   {
      strncpy(intPort, p, 6);
      intPort[5] = '\0';
   }


Which means there are three theoretical possibilities.
1. Pointers cannot be null at lines 583 and 584 (verified somewhere before the call). Then no further checking is necessary.
2. Pointers must be checked before assignments, furthers checks removed.
3. Intended check was not for pointers, but for non-empty string.

My guess would be the point 2.
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1452

PostPosted: Mon Mar 07, 2016 9:00 am    Post subject: Reply with quote

https://github.com/miniupnp/miniupnp/commit/dc9eb0df1c8ee36101b7c269a4695d247d0a48cc
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
fox88



Joined: 05 Feb 2015
Posts: 9

PostPosted: Sat Mar 12, 2016 9:18 pm    Post subject: Reply with quote

Sorry, I should have posted the topic in miniupnpc Bugs (it could be moved to the proper subforum, though).
Anyway, there is another unnecessary check in file miniupnpc.c at line 685:
Code:
if(desc[i].xml) {
   free(desc[i].xml);

According to standards: If ptr is a null pointer, no action occurs.
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1452

PostPosted: Mon Mar 14, 2016 9:35 am    Post subject: Reply with quote

fox88 wrote:
Sorry, I should have posted the topic in miniupnpc Bugs (it could be moved to the proper subforum, though).
Anyway, there is another unnecessary check in file miniupnpc.c at line 685:
Code:
if(desc[i].xml) {
   free(desc[i].xml);

According to standards: If ptr is a null pointer, no action occurs.

you are right, I should fix that.
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpd Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.