summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-09-27 17:00:38 -0400
committerRich Felker <dalias@aerifal.cx>2011-09-27 17:00:38 -0400
commit7e76095180a5d64821e21900b85dbd8829e2d90d (patch)
tree639b5ae285a949a7d7d30628097b8a0d7afee4b8 /src
parentf135ef3f343b824c5039e3dbbc31b5545fbe7a12 (diff)
downloadmusl-7e76095180a5d64821e21900b85dbd8829e2d90d.tar.gz
musl-7e76095180a5d64821e21900b85dbd8829e2d90d.tar.bz2
musl-7e76095180a5d64821e21900b85dbd8829e2d90d.tar.xz
musl-7e76095180a5d64821e21900b85dbd8829e2d90d.zip
improve error handling in mntent stuff...
not sure if this is correct/ideal. it needs further attention.
Diffstat (limited to 'src')
-rw-r--r--src/linux/mntent.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/linux/mntent.c b/src/linux/mntent.c
index 48c85bd6..f1516252 100644
--- a/src/linux/mntent.c
+++ b/src/linux/mntent.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#include <mntent.h>
+#include <errno.h>
FILE *setmntent(const char *name, const char *mode)
{
@@ -22,7 +23,13 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle
do {
fgets(linebuf, buflen, f);
- if (feof(f)) return NULL;
+ if (feof(f) || ferror(f)) return 0;
+ if (!strchr(linebuf, '\n')) {
+ if (fseeko(f, -(off_t)strlen(linebuf), SEEK_CUR))
+ fscanf(f, "%*[^\n]%*[\n]");
+ errno = ERANGE;
+ return 0;
+ }
cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
&mnt->mnt_freq, &mnt->mnt_passno);
@@ -50,7 +57,7 @@ struct mntent *getmntent(FILE *f)
int addmntent(FILE *f, const struct mntent *mnt)
{
- fseek(f, 0, SEEK_END);
+ if (fseek(f, 0, SEEK_END)) return 1;
return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
mnt->mnt_freq, mnt->mnt_passno) < 0;