Fix #253: use reentrant getmntent_r() API

When iterating over the system fstab file to call fsck, Finit calls the
helper function ismnt(), which opens /proc/mounts to make sure mounted
file systems are not fsck'ed.  Both the main function and ismnt() used
the same non-reentrant getmntent() API which caused ismnt() to set the
fstab pointer for the first out of whack.

This change replaces getmntent() in the two critical functions with the
getmntent_r() API instead.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-05-01 21:43:13 +02:00
1 parent 1015124530
commit d6c55282ef
3 files changed
+9 -4

No files matched your search

+3 -1
View File
@@ -488,7 +488,9 @@ static int hasopt(char *opts, char *opt)
int ismnt(char *file, char *dir, char *mode)
{
struct mntent mount;
struct mntent *mnt;
char buf[256];
int found = 0;
FILE *fp;
@@ -496,7 +498,7 @@ int ismnt(char *file, char *dir, char *mode)
if (!fp)
return 0; /* Dunno, maybe not */
while ((mnt = getmntent(fp))) {
while ((mnt = getmntent_r(fp, &mount, buf, sizeof(buf)))) {
if (!strcmp(mnt->mnt_dir, dir)) {
if (mode) {
if (hasopt(mnt->mnt_opts, mode))