]> git.sur5r.net Git - i3/i3status/commitdiff
Prevent potential crash if glob() fails 290/head
authorOlivier Gayot <olivier.gayot@sigexec.com>
Wed, 20 Jun 2018 11:41:59 +0000 (13:41 +0200)
committerOlivier Gayot <olivier.gayot@sigexec.com>
Wed, 20 Jun 2018 12:20:17 +0000 (14:20 +0200)
Calling globfree(NULL) is undefined behaviour. In Linux (glibc), it
results in a segmentation fault.

It is also undefined behaviour to call globfree(&pglob) if a previous
call to glob(&pglob) returned an error.

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
src/print_battery_info.c

index 72c2d6f4af0f7e9621c83910b0dc3e68edf0b7e8..04b5a251feb6f0c7eb8674b4fd7ad095dd9079cf 100644 (file)
@@ -459,8 +459,8 @@ static bool slurp_all_batteries(struct battery_info *batt_info, yajl_gen json_ge
             is_found = true;
             add_battery_info(batt_info, &batt_buf);
         }
+        globfree(&globbuf);
     }
-    globfree(&globbuf);
     free(globpath);
 
     if (!is_found) {