[Nut-upsdev] segmentation fault in blazer_status().

Arjen de Korte nut+devel at de-korte.org
Fri Nov 5 17:12:33 UTC 2010


Citeren Pawel Sikora <pluto op agmk.net>:

> (gdb) up
> #1  blazer_status (cmd=<value optimized out>) at blazer.c:214
>
> (gdb) p val
> $1 = 0x0

Excellent, I missed checking for a NULL pointer somewhere in the code.  
Good catch!

> 199|         for (i = 0, val = strtok_r(buf+1, " ", &last);  
> status[i].var; i++, val = strtok_r(NULL, " \r\n", &last)) {
> 200|
> 201|                 if (!val) {
> 202|                         upsdebugx(2, "%s: parsing failed", __func__);
> 203|                         return -1;
> 204|                 }
> 205|
> 206|                 if (strspn(val, "0123456789.") != strlen(val)) {
> 207|                         upsdebugx(2, "%s: non numerical value  
> [%s]", __func__, val);
> 208|                         continue;
> 209|                 }
> 210|
> 211|                 dstate_setinfo(status[i].var, status[i].fmt,  
> status[i].conv(val, NULL));
> 212|         }

                if (!val) {
                        upsdebugx(2, "%s: parsing failed", __func__);
                        return -1;
                }

> 213|
> 214+-------> if (strspn(val, "01") != 8) {
> 215|                 upsdebugx(2, "Invalid status [%s]", val);
> 216|                 return -1;
> 217|         }
>
> except this rare segfauls the nut-2.4.3 package is great and works fine.
> i can provide more debugging details if needed.

Most likely this won't be needed. It is pretty obvious from the trace  
what is happening. The last chunk of data from the UPS (with the  
status information) is lost and the strspn() function receives NULL  
pointer indicating there is no more data). Try out the above  
modification and let us know if this fixes the segfaults.

Best regards, Arjen
-- 
Please keep list traffic on the list (off-list replies will be rejected)




More information about the Nut-upsdev mailing list