[wiki] [sites] Fix seg-fault in getbattery. The code failed to check for co == NULL after the first call to readline. || Don Allen

From: <hg_AT_suckless.org>
Date: Sun, 1 Jan 2012 14:26:04 +0100 (CET)

changeset: 808:d2b7a0ed2517
tag: tip
user: Don Allen <donaldcallen_AT_gmail.com>
date: Sun Jan 01 08:21:37 2012 -0500
files: dwm.suckless.org/dwmstatus/new-acpi-battery.c
description:
Fix seg-fault in getbattery. The code failed to check for co == NULL after the first call to readline.
If NULL, a seg-fault would occur on the reference to co[0]. This change fixes that.


diff -r 9b99bf4c9656 -r d2b7a0ed2517 dwm.suckless.org/dwmstatus/new-acpi-battery.c
--- a/dwm.suckless.org/dwmstatus/new-acpi-battery.c Thu Dec 29 02:20:41 2011 +0100
+++ b/dwm.suckless.org/dwmstatus/new-acpi-battery.c Sun Jan 01 08:21:37 2012 -0500
_AT_@ -33,8 +33,8 @@
         remcap = -1;
 
         co = readfile(base, "present");
- if (co[0] != '1') {
- free(co);
+ if (co == NULL || co[0] != '1') {
+ if (co != NULL) free(co);
                 return smprintf("not present");
         }
         free(co);
Received on Sun Jan 01 2012 - 14:26:04 CET

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 19:31:55 CEST