[Nut-upsdev] nut-scanner pthread issue

Michal Hlavinka mhlavink at redhat.com
Thu Sep 6 13:24:07 UTC 2012


Hi,

the terminating part of nut-scanner can crash in pthread code, because 
some threads won't exist. For example snmp part:

==============================
	if( allow_snmp && nutscan_avail_snmp ) {
		if( start_ip == NULL ) {
			printq(quiet,"No start IP, skipping SNMP\n");
		}
		else {
			printq(quiet,"Scanning SNMP bus.\n");
#ifdef HAVE_PTHREAD
			if( pthread_create(&thread[TYPE_SNMP],NULL,run_snmp,&snmp_sec)) {
				nutscan_avail_snmp = 0;
			}
#else
			dev[TYPE_SNMP] = nutscan_scan_snmp(start_ip,end_ip,timeout,&snmp_sec);
#endif /* HAVE_PTHREAD */
		}
	}
==============================
if start_ip==NULL, pthread is not created, but later...

	if( allow_snmp && nutscan_avail_snmp && thread[TYPE_SNMP]) {
		pthread_join(thread[TYPE_SNMP],NULL);
	}

it calls pthread_join with threan[TYPE_SNMP]==0,
pthread_join(0, ?) behaviour is undefined, on my system undefined=crashes.

I used attached patch to get rid of it.

Cheers,
Michal

/me is back from vacation and going to another one tmrw, so I won't be 
reachable for some time (again)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nut-2.6.5-pthreadfix.patch
Type: text/x-patch
Size: 1279 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20120906/989800fb/attachment.bin>


More information about the Nut-upsdev mailing list