[Nut-upsdev] [PATCH] nut crashes when port= is omitted

Michal Hlavinka mhlavink at redhat.com
Wed Jul 21 11:45:39 UTC 2010


Hi,

I've found that upsdrvctl crashes when there is not ports= specified ups.conf

#0  __strrchr_sse2 () at ../sysdeps/x86_64/strrchr.S:33
#1  xbasename (file=0x0) at common.c:266
#2  stop_driver (ups=0x1e163e0) at upsdrvctl.c:135
#3  send_all_drivers (command=0x4020f0 <stop_driver>) at upsdrvctl.c:446
#4  main (argc=1, argv=0x7ffff30be9c0) at upsdrvctl.c:565



 stop_driver (ups=0x1e163e0) at upsdrvctl.c:135:
	if (ret != 0) {
		snprintf(pidfn, sizeof(pidfn), "%s/%s-%s.pid", altpidpath(),
			ups->driver, xbasename(ups->port));
		ret = stat(pidfn, &fs);
	}

ups->port is NULL which makes xbasename(NULL) crash. Seems this is the only 
problem with wrong configuration. During quick testing I did not find any other 
sensitive place or value.

How to reproduce this crash:
1)add ups to ups.conf, omit port configuration
2)run upsdrvctl stop


There is nothing checking ups configuration is ok for upsdrvctl. For daemon 
there is check in server/conf.c upsconf_add. I've moved that checking code to 
separate function upsconf.c : validate_upsconf and used this function from 
upsconf_add and from upsdrvctl.c , this was more intrusive than it seemed. See 
attached patch (tested). Simpler way would be just adding validate_upsconf to 
upsdrvctl.c but it'd lead to code duplication. Any comments?

Michal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nut-portcrash.patch
Type: text/x-patch
Size: 5024 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20100721/e4e42d35/attachment.bin>


More information about the Nut-upsdev mailing list