>From 7fac4fbbd7203d2fcf3be257872e3c7508b86402 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 26 May 2020 18:04:26 +0200 Subject: [PATCH 7/8] mountlist: Make more robust in multithreaded applications. * lib/mountlist.c (setmntent, read_file_system_list): Pass an 'e' flag to fopen. * modules/mountlist (Depends-on): Add fopen-gnu. --- ChangeLog | 7 +++++++ lib/mountlist.c | 10 +++++----- modules/mountlist | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 162b861..b30f4b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2020-05-26 Bruno Haible + mountlist: Make more robust in multithreaded applications. + * lib/mountlist.c (setmntent, read_file_system_list): Pass an 'e' flag + to fopen. + * modules/mountlist (Depends-on): Add fopen-gnu. + +2020-05-26 Bruno Haible + sethostname: Make more robust in multithreaded applications. * lib/sethostname.c (sethostname): Pass an 'e' flag to fopen. * modules/sethostname (Depends-on): Add fopen-gnu. diff --git a/lib/mountlist.c b/lib/mountlist.c index 7abe024..4cb19c8 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -125,7 +125,7 @@ #ifdef MOUNTED_GETMNTENT1 # if !HAVE_SETMNTENT /* Android <= 4.4 */ -# define setmntent(fp,mode) fopen (fp, mode) +# define setmntent(fp,mode) fopen (fp, mode "e") # endif # if !HAVE_ENDMNTENT /* Android <= 4.4 */ # define endmntent(fp) fclose (fp) @@ -460,7 +460,7 @@ read_file_system_list (bool need_fs_type) (and that code is in previous versions of this function), however libmount depends on libselinux which pulls in many dependencies. */ char const *mountinfo = "/proc/self/mountinfo"; - fp = fopen (mountinfo, "r"); + fp = fopen (mountinfo, "re"); if (fp != NULL) { char *line = NULL; @@ -794,7 +794,7 @@ read_file_system_list (bool need_fs_type) char *table = "/etc/mnttab"; FILE *fp; - fp = fopen (table, "r"); + fp = fopen (table, "re"); if (fp == NULL) return NULL; @@ -852,7 +852,7 @@ read_file_system_list (bool need_fs_type) by the kernel. */ errno = 0; - fp = fopen (table, "r"); + fp = fopen (table, "re"); if (fp == NULL) ret = errno; else @@ -924,7 +924,7 @@ read_file_system_list (bool need_fs_type) # endif errno = 0; - fp = fopen (table, "r"); + fp = fopen (table, "re"); if (fp == NULL) ret = errno; else diff --git a/modules/mountlist b/modules/mountlist index 11cf809..5bb45ed 100644 --- a/modules/mountlist +++ b/modules/mountlist @@ -8,6 +8,7 @@ m4/fstypename.m4 m4/mountlist.m4 Depends-on: +fopen-gnu getline stdbool stdint -- 2.7.4