]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/shared/openssl-util.h
tree-wide: reset the cleaned-up variable in cleanup functions
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Feb 2021 13:18:30 +0000 (14:18 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Feb 2021 16:15:11 +0000 (17:15 +0100)
commitfd421c4adc7406de02e03e2f7ceede2cc6e1d9d4
tree1d66cea62fbdad79689c0403bb42c7beb0a359ce
parent75db809ae583ef7287e39738195c0825c3070843
tree-wide: reset the cleaned-up variable in cleanup functions

If the cleanup function returns the appropriate type, use that to reset the
variable. For other functions (usually the foreign ones which return void), add
an explicit value to reset to.

This causes a bit of code churn, but I think it might be worth it. In a
following patch static destructors will be called from a fuzzer, and this
change allows them to be called multiple times. But I think such a change might
help with detecting unitialized code reuse too. We hit various bugs like this,
and things are more obvious when a pointer has been set to NULL.

I was worried whether this change increases text size, but it doesn't seem to:

-Dbuildtype=debug:
before "tree-wide: return NULL from freeing functions":
-rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0*
-rwxrwxr-x 1 zbyszek zbyszek 4494520 Feb 16 15:06 build/systemd*
after "tree-wide: return NULL from freeing functions":
-rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0*
-rwxrwxr-x 1 zbyszek zbyszek 4494576 Feb 16 15:10 build/systemd*
now:
-rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0*
-rwxrwxr-x 1 zbyszek zbyszek 4494640 Feb 16 15:15 build/systemd*

-Dbuildtype=release:
before "tree-wide: return NULL from freeing functions":
-rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0*
-rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:09 build-rawhide/systemd*
after "tree-wide: return NULL from freeing functions":
-rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0*
-rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:10 build-rawhide/systemd*
now:
-rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0*
-rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:16 build-rawhide/systemd*

I would expect that the compiler would be able to elide the setting of a
variable if the variable is never used again. And this seems to be the case:
in optimized builds there is no change in size whatsoever. And the change in
size in unoptimized build is negligible.

Something strange is happening with size of libsystemd: it's bigger in
optimized builds. Something to figure out, but unrelated to this patch.
31 files changed:
src/basic/capability-util.h
src/basic/dlfcn-util.h
src/basic/fd-util.h
src/basic/fileio.c
src/basic/gcrypt-util.h
src/basic/macro.h
src/basic/selinux-util.c
src/basic/selinux-util.h
src/core/apparmor-setup.c
src/core/socket.c
src/home/homed-manager.c
src/home/homework-luks.c
src/home/user-record-sign.c
src/import/curl-util.h
src/journal-remote/microhttpd-util.h
src/journal/journalctl.c
src/libsystemd/sd-journal/compress.c
src/partition/repart.c
src/resolve/resolved-dnstls-gnutls.c
src/shared/acl-util.h
src/shared/blkid-util.h
src/shared/cryptsetup-util.h
src/shared/firewall-util-iptables.c
src/shared/libmount-util.h
src/shared/module-util.h
src/shared/mount-util.h
src/shared/openssl-util.h
src/shared/pkcs11-util.h
src/shared/pwquality-util.h
src/shared/seccomp-util.h
src/udev/udev-ctrl.c