[Pkg-xfce-devel] Bug#491480: I think i fixed the bug

Daniel Gibson metalcaedes at gmail.com
Wed Aug 6 01:20:32 UTC 2008

Good new everyone,

I found the bug (or at least the one that made the plugin crash for _me_).
It's in panel-plugin/acpi.c in refresh_acpi().
The (broken) code is at line 475:

case STATE:
        file = g_strdup_printf ("%s/%s/state", ACPI_DIR_FAN, cf->devicename);
        cf->raw_value = strcmp(get_acpi_value(file), "on")==0 ? 1.0 : 0.0;

The problem is, that get_acpi_value() (in contrast to
get_acpi_zone_value() for example) expects a _full_ path to the file.
So the code has to be changed to:

case STATE:
	// get_acpi_value() expects a _full_ path (unlike get_acpi_zone_value() etc)!
        file = g_strdup_printf ("%s/%s/%s/state", ACPI_PATH,
ACPI_DIR_FAN, cf->devicename);
        cf->raw_value = strcmp(get_acpi_value(file), "on")==0 ? 1.0 : 0.0;

otherwise get_acpi_value() returns NULL which causes strcmp() to crash.
Also it should be checked first, whether get_acpi_value() has returned
NULL to prevent a crash if (for whatever reason) the fan isn't listed
in /proc/acpi anymore or something like that.

Last but not least strcmp() doesn't work there for me, as
get_acpi_values() returns "on\n" - so it should be replaced by
I've attached a diff for panel-plugin/acpi.c that fixes the crash by
using the right path for the file, checks if get_acpi_value() has
returned NULL (and prevents a possible crash) and uses strncmp to()
compare the extracted content of the file with "on", so we don't have
to care whether the file contained "on" or "on\n"

- Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_acpi.diff
Type: text/x-diff
Size: 1466 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/pkg-xfce-devel/attachments/20080806/aaba98f5/attachment.diff 

More information about the Pkg-xfce-devel mailing list