From 6bbb893b90e2dcb05fb310ba4608f9c9dc587845 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 19 Oct 2023 19:42:07 +0200 Subject: [PATCH] rm-rf: Make sure we rewinddir() before readdir() 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c index 4664215e90..e1dc4024dc 100644 --- a/src/shared/rm-rf.c +++ b/src/shared/rm-rf.c @@ -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) {