kwo pushed a commit to branch master. http://git.enlightenment.org/e16/e16-epplets.git/commit/?id=beae0b229aedf0df0480ed74f2db471aa5853da3
commit beae0b229aedf0df0480ed74f2db471aa5853da3 Author: Kim Woelders <[email protected]> Date: Fri Aug 27 17:06:49 2021 +0200 E-Mountbox: Fix potential segv when parsing /etc/fstab --- epplets/E-Mountbox.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/epplets/E-Mountbox.c b/epplets/E-Mountbox.c index 67cdffb..7744f4f 100644 --- a/epplets/E-Mountbox.c +++ b/epplets/E-Mountbox.c @@ -1140,44 +1140,25 @@ ParseFstab(void) { FILE *f; char s[1024]; - char *token = NULL; - char *info[4]; - int i; + char fs_spec[256], fs_file[256], fs_mntops[256]; if (!(f = fopen(FSTAB, "r"))) return 0; + *s = 0; for (; fgets(s, sizeof(s), f);) { /* skip comments and blank lines */ if (!(*s) || (*s == '\n') || (*s == '#')) - { - continue; - } - - for (i = 0; i < 4; i++) - info[i] = NULL; + continue; /* parse out tokens we need */ - i = 0; - token = strtok(s, " \t"); - if (token) - { - info[i++] = strdup(token); - } - while ((token = strtok(NULL, " \t"))) - { - info[i++] = strdup(token); - } + fs_spec[0] = fs_file[0] = fs_mntops[0] = '\0'; + sscanf(s, "%63s %255s %*s %255s", fs_spec, fs_file, fs_mntops); /* see if device is user-mountable */ - if (strstr(info[3], "user")) - { - AddMountPoint(info[0], info[1]); - } - - for (i = 0; i < 4; i++) - free(info[i]); + if (strstr(fs_mntops, "user")) + AddMountPoint(fs_spec, fs_file); } fclose(f); --
