From: Daan De Meyer Date: Thu, 19 Oct 2023 17:42:07 +0000 (+0200) Subject: rm-rf: Make sure we rewinddir() before readdir() X-Git-Tag: v255-rc1~187 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bbb893b90e2dcb05fb310ba4608f9c9dc587845;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c index 4664215e906..e1dc4024dc6 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) {