]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rm-rf: Make sure we rewinddir() before readdir()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 19 Oct 2023 17:42:07 +0000 (19:42 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 20 Oct 2023 10:55:53 +0000 (11:55 +0100)
We don't know what state the passed in file descriptor is in. Let's
make sure we rewind it before iterating over it.

Fixes #29606

src/shared/rm-rf.c

index 4664215e906204123587d7b3b63e0b0f78aa5861..e1dc4024dc68518e9afa14cc9d0f8b326390b5fc 100644 (file)
@@ -365,6 +365,10 @@ static int rm_rf_children_impl(
                                                                strna(path));
                                 }
                         }
+
+                        /* Make sure we reset the iterator since we don't know the state the passed in file
+                         * descriptor is in. */
+                        rewinddir(d);
                 }
 
                 FOREACH_DIRENT_ALL(de, d, return -errno) {