]> Savannah Git Hosting - gnulib.git/commitdiff
fts: fail gracefully when out of memory
authorChuanGang Jiang <jiangchuanganghw@outlook.com>
Mon, 27 Feb 2023 11:46:12 +0000 (11:46 +0000)
committerBruno Haible <bruno@clisp.org>
Thu, 2 Mar 2023 21:07:25 +0000 (22:07 +0100)
* lib/fts.c (fts_read): Set errno==ENOMEM and return NULL
when setup_dir() fails, rather than hitting an assertion later.

ChangeLog
lib/fts.c

index 80d90c01e1e96a95b87567c69b8a71676413b59c..c7a613148645fd3021053200a74f5e4bf1308f81 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-02-27  ChuanGang Jiang  <jiangchuanganghw@outlook.com>
+
+       fts: fail gracefully when out of memory
+       * lib/fts.c (fts_read): Set errno==ENOMEM and return NULL
+       when setup_dir() fails, rather than hitting an assertion later.
+
 2023-02-26  Bruno Haible  <bruno@clisp.org>
 
        dfa: Avoid warnings with some Apple clang versions.
index 34fe6416407cd328d96e171b8d2babbecfeea52d..0deafa4ff2011bcd51921e8d7b23285496824a27 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1,6 +1,6 @@
 /* Traverse a file hierarchy.
 
-   Copyright (C) 2004-2022 Free Software Foundation, Inc.
+   Copyright (C) 2004-2023 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -980,7 +980,11 @@ next:   tmp = p;
                         }
                         free_dir(sp);
                         fts_load(sp, p);
-                        setup_dir(sp);
+                        if (! setup_dir(sp)) {
+                                free_dir(sp);
+                                __set_errno (ENOMEM);
+                                return (NULL);
+                        }
                         goto check_for_dir;
                 }