On 2026/01/25 20:55, BALATON Zoltan wrote:
On Sun, 25 Jan 2026, Akihiko Odaki wrote:
nvme-ns has a use-after-free of a formatted string, so fix it by
embedding a fixed-length buffer to the object. Embedding a buffer lets
me avoid a chore to add a function to call g_free().
Isn't that where g_autofree would help?
Unfortunately no. It helps only if the lifetime is bound to a scope. In
this case, the lifetime is bound to an object.
But I don't want to worry about a buffer overflow, so let the compiler
check that the buffer won't overflow; C is so restrictive that it cannot
enforce the existence of g_free(). Compilers can check the length of
formatted string on the other hand.
Then GCC started complaining about buffer overflow, so let's treat them.
Fortunately, the potential buffer overflows it detected are not
user-facing or very subtle. Treating them by growing buffers can improve
robustness with practically no cost.
This is useful but maybe there's a better fix for some of these than
arbitrarily enlarging buffers but I don't care enough about these to judge.
They can be fixed with g_autofree. I think either enlarging buffers or
using g_autofree is fine; differences between them are insignificant.
Regards,
Akihiko Odaki