Bug 12566 - Dead code in source3/nmbd/nmbd.c
Summary: Dead code in source3/nmbd/nmbd.c
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Other (show other bugs)
Version: 4.5.5
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Jeremy Allison
QA Contact: Samba QA Contact
Depends on:
Reported: 2017-02-07 06:48 UTC by shqking
Modified: 2017-02-09 20:59 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description shqking 2017-02-07 06:48:29 UTC
Suspicious dead code is found in source3/nmbd.c:1080.

The code snippet is as following.

1080	if( False == register_my_workgroup_and_names() ) {
1081		kill_async_dns_child();
1082		exit_daemon( "NMBD failed when creating my workgroup.", EACCES);
1083	}

The return value of function "register_my_workgroup_and_names" is checked with "False". If it returns False, the code at lines 1081 and 1082 will be executed.

However, according to the definition of function "register_my_workgroup_and_names" at source3/nmbd.c:114, there is only one return site, i.e. "return True" at line 205.

Hence, the check at line 1080 will always take the false branch, and lines 1081 and 1082 will never be executed.

Besides, I'm not sure  whether it is just a dead code issue, or there are any implementation errors in function "register_my_workgroup_and_names"?


Comment 1 shqking 2017-02-07 06:52:14 UTC

The suspicious dead code is found in source3/nmbd/nmbd_mynames.c:1080.

Sorry for the writing mistakes.
Comment 2 shqking 2017-02-07 06:58:28 UTC
Update again...

The dead code is found in source3/nmbd/nmbd.c:1080.

The definition of function "register_my_workgroup_and_names" is at source3/nmbd/nmbd_mynames.c:114.

I feel terribly sorry for my mistake, and hope that it won't bring you much inconvenience. :)
Comment 3 Jeremy Allison 2017-02-09 20:59:42 UTC
Yes, this report is theoretically correct. Having said that, the better way to fix this is to change the code inside register_my_workgroup_and_names() to be able to correctly report back any malloc or other errors to the caller, rather then just (void)'ing out the returns as it does now.

This code needs clean up to handle errors better, and was written a long time ago.