]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: Prevent double free of reused FILE*
authorWieland Hoffmann <themineo@gmail.com>
Thu, 2 May 2019 18:10:08 +0000 (20:10 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 3 May 2019 11:22:36 +0000 (13:22 +0200)
When the .automount unit file already existed for any reason in the
`normal-dir` passed to `systemd-fstab-generator`, but the normal .mount unit
file did not, `f` was closed (but _not_ set to NULL). The call to
`generator_open_unit_file(..., automount_name, &f)` then failed because the
.mount unit file already existed. Now `f` did not point to an open FILE and the
later cleanup from the `_cleanup_fclose_` attribute failed with a double free.
Reset `f` to NULL before reusing it.

src/fstab-generator/fstab-generator.c

index 28ae48d551a87f476a3848b59337c87350fbe700..76270aec17f22ca4c284f699c9764b5e7738de1c 100644 (file)
@@ -463,7 +463,7 @@ static int add_mount(
                 if (r < 0)
                         return log_error_errno(r, "Failed to generate unit name: %m");
 
-                fclose(f);
+                f = safe_fclose(f);
 
                 r = generator_open_unit_file(dest, "/etc/fstab", automount_name, &f);
                 if (r < 0)