X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Flinux%2Fmntent.c;h=3eafba5e0b387ce98e0aefde2bbdaf8288757af9;hb=fcaec912ed406659832f452e71a6c965308362dd;hp=26d045c24a1067b4a6af56d29e88c58304ea9baf;hpb=2c4e9e6e4b570f4dbbcc5f2402b0257a3b43380a;p=musl diff --git a/src/linux/mntent.c b/src/linux/mntent.c index 26d045c2..3eafba5e 100644 --- a/src/linux/mntent.c +++ b/src/linux/mntent.c @@ -1,6 +1,7 @@ #include #include #include +#include FILE *setmntent(const char *name, const char *mode) { @@ -22,11 +23,16 @@ 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')) { + 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); - } while (cnt >= 8 && linebuf[n[0]] != '#'); + } while (cnt < 2 || linebuf[n[0]] == '#'); linebuf[n[1]] = 0; linebuf[n[3]] = 0; @@ -50,7 +56,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;