mirror of
https://git.musl-libc.org/git/musl
synced 2025-10-05 21:12:41 +02:00
hasmntopt: match only whole options not arbitrary substrings
the man page for this nonstandardized function has historically documented it as scanning for a substring; however, this is functionally incorrect (matches the substring "atime" in the "noatime" option, for example) and differs from other existing implementations. with the change made here, it should match glibc and other implementations, only matching whole options delimited by commas or separated from a value by an equals sign.
This commit is contained in:
@@ -115,5 +115,13 @@ int addmntent(FILE *f, const struct mntent *mnt)
|
||||
|
||||
char *hasmntopt(const struct mntent *mnt, const char *opt)
|
||||
{
|
||||
return strstr(mnt->mnt_opts, opt);
|
||||
size_t l = strlen(opt);
|
||||
char *p = mnt->mnt_opts;
|
||||
for (;;) {
|
||||
if (!strncmp(p, opt, l) && (!p[l] || p[l]==',' || p[l]=='='))
|
||||
return p;
|
||||
p = strchr(p, ',');
|
||||
if (!p) return 0;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user