mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
stdbuf: avoid even the appearance of a possible use-after-free
There was an execution path by which "libstdbuf" could be used after being freed, but that would happen only if there were no libstdbuf.so alongside the stdbuf program and there had been an installation error leading to absence of the file, PKGLIBDIR/libstdbuf.so. * src/stdbuf.c (set_LD_PRELOAD): Rearrange loop to make it perfectly clear that there is no possibility of use-after-free. Steve Grubb reported this possible use-after-free of "libstdbuf".
This commit is contained in:
1 parent
e6067bcb04
commit
2895f44e89
1 file changed
+5
-2
+5
-2
@@ -209,7 +209,7 @@ set_LD_PRELOAD (void)
|
||||
char const *const *path = search_path;
|
||||
char *libstdbuf;
|
||||
|
||||
do
|
||||
while (true)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
@@ -224,8 +224,11 @@ set_LD_PRELOAD (void)
|
||||
if (stat (libstdbuf, &sb) == 0) /* file_exists */
|
||||
break;
|
||||
free (libstdbuf);
|
||||
|
||||
++path;
|
||||
if ( ! *path)
|
||||
error (EXIT_CANCELED, 0, _("failed to find %s"), quote (LIB_NAME));
|
||||
}
|
||||
while (*++path);
|
||||
|
||||
/* FIXME: Do we need to support libstdbuf.dll, c:, '\' separators etc? */
|
||||
|
||||
|
||||
Reference in new issue
Block a user