summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2010-03-16 10:57:44 +0100
committerKay Sievers <kay.sievers@vrfy.org>2010-03-16 10:57:44 +0100
commitd44c27c5ab71dbbcfcf4745977027502309dd795 (patch)
treedc8704d6a807c96c8d53888e9043592ff215567c
parentb41102757d9d1f71aa04f3d264d57d573360d957 (diff)
firmware: fix possible segfault when firmware device goes away while loading
Thanks to Ruediger Oertel.
-rw-r--r--extras/firmware/firmware.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/extras/firmware/firmware.c b/extras/firmware/firmware.c
index 16455dec8f..92f0918c6f 100644
--- a/extras/firmware/firmware.c
+++ b/extras/firmware/firmware.c
@@ -63,8 +63,10 @@ static bool copy_firmware(struct udev *udev, const char *source, const char *tar
if (fwrite(buf, size, 1, ftarget) == 1)
ret = true;
exit:
- fclose(ftarget);
- fclose(fsource);
+ if (ftarget != NULL)
+ fclose(ftarget);
+ if (fsource != NULL)
+ fclose(fsource);
free(buf);
return ret;
}
@@ -178,7 +180,8 @@ int main(int argc, char **argv)
if (unlink(misspath) == 0)
util_delete_path(udev, misspath);
- set_loading(udev, loadpath, "1");
+ if (!set_loading(udev, loadpath, "1"))
+ goto exit;
util_strscpyl(datapath, sizeof(datapath), udev_get_sys_path(udev), devpath, "/data", NULL);
if (!copy_firmware(udev, fwpath, datapath, statbuf.st_size)) {