]> git.ipfire.org Git - thirdparty/kmod.git/commit
strbuf: Invalidate (only) when stolen
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 12 Nov 2024 15:34:58 +0000 (09:34 -0600)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Sun, 17 Nov 2024 21:35:13 +0000 (15:35 -0600)
commit25f2b2e09608e4be9bba6cb5c455356c7858b712
tree754075bb1f9d3f7e566a9c511d9c5fdf2ac457d3
parentb8776806de69062ec8b7e69c56d67694fbad9f4a
strbuf: Invalidate (only) when stolen

The main for strbuf_steal() to free() on error was to allow the caller
to pass the NULL up the stack with just a return call to
strbuf_steal().

However this is error-prone and surprising that the buffer is still
invalidated on error. Provide an strbuf cleanup attribute that can be
used for the same purpose and make sure that when the string is stolen,
it's set to NULL, so there's no dangling pointer around.

Since we run the  testsuite with AddressSanitizer, a simple test can be
added to make sure the stolen string becomes valid when the attribute is
used.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
libkmod/libkmod-module.c
shared/strbuf.c
shared/strbuf.h
testsuite/test-strbuf.c