Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 141205 - dhcpcd: -v option causes segfault
Summary: dhcpcd: -v option causes segfault
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Roy Marples (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-20 13:34 UTC by Bert van Leeuwen
Modified: 2006-07-24 08:51 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bert van Leeuwen 2006-07-20 13:34:49 UTC
e.g. "dhcpcd -v 1 eth1" gives:
Segmentation fault

I looked at the code briefly, and fixed the problem by doing the following:

--- logger.c.orig       2006-07-20 22:18:52.000000000 +0200
+++ logger.c    2006-07-20 22:15:11.000000000 +0200
@@ -24,15 +24,16 @@
        [LOG_EMERG]   = "LOG_EMERG",
        [LOG_ALERT]   = "LOG_ALERT",
        [LOG_CRIT]    = "LOG_CRIT",
        [LOG_ERR]     = "LOG_ERR",
        [LOG_WARNING] = "LOG_WARNING",
        [LOG_NOTICE]  = "LOG_NOTICE",
        [LOG_INFO]    = "LOG_INFO",
-       [LOG_DEBUG]   = "LOG_DEBUG"
+       [LOG_DEBUG]   = "LOG_DEBUG",
+       [LOG_DEBUG+1] = 0
 };

 int log_to_level(const char *priority)
 {
        int i = 0;
        while (syslog_level[i]) {
                if (!strcmp(priority, syslog_level[i])) return i;



That is to say, the "while (syslog_level[i])" construct wasn't guaranteed to terminate after the LOG_DEBUG entry unless there happened to be a zero in that memory location by accident...

The whole argument parsing in dhcpcd.c can actually be improved (made more robust) by ripping out all the code and replacing it with the standard optarg/getopt framework in unistd.h. Not sure who is the maintainer of this code, but I'd be happy to step in and change this.
Comment 1 Roy Marples (RETIRED) gentoo-dev 2006-07-21 03:01:41 UTC
Fixed in dhcpcd-2.0.8-r1, also patched upstream svn.

If you want to re-write the option parsing code using optarg/getopt then by all means go for it - all patches gratefully accepted :) But please always send patches against the latest version in portage.
Comment 2 Roy Marples (RETIRED) gentoo-dev 2006-07-24 07:50:36 UTC
(In reply to comment #0)
> The whole argument parsing in dhcpcd.c can actually be improved (made more
> robust) by ripping out all the code and replacing it with the standard
> optarg/getopt framework in unistd.h.

I'm doing this now, so don't waste your time on this :)
Comment 3 Bert van Leeuwen 2006-07-24 08:06:34 UTC
(In reply to comment #2)
> I'm doing this now, so don't waste your time on this :)

Excellent, thanks for letting me know! I as considering tackling it this evening :)
Comment 4 Roy Marples (RETIRED) gentoo-dev 2006-07-24 08:51:40 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > I'm doing this now, so don't waste your time on this :)
> 
> Excellent, thanks for letting me know! I as considering tackling it this
> evening :)
> 

Infact it you plan on doing any dhcpcd patches, please checkout the lastest via SVN as I've just re-styled the entire codebase in GNU C style as the existing code was so hard to read.

http://developer.berlios.de/svn/?group_id=4229