diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-06-24 00:12:19 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-06-24 00:12:19 +0200 |
commit | 56edc16eb80a813473b3214d41ca0f808d566d6e (patch) | |
tree | 25a6e4647d73d90e47f45e2e320dfd1654eb876b /src | |
parent | 7107a975a849ff4a7c437a5490a5f4ddc9f9c9a9 (diff) |
fixed buffer overwrite by libc functions basename/dirname, open(...) should set mode to 0 instead of ignoring it
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/options.c | 14 | ||||
-rw-r--r-- | src/utils.c | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/options.c b/src/options.c index e390ac8..e287580 100644 --- a/src/options.c +++ b/src/options.c @@ -117,22 +117,26 @@ static void usage(const char *arg0, int print_copyright); static int parse_path(opt_ptr *d, char *some_path) { int rc = 1; - char path[PATH_MAX]; + char path_dir[PATH_MAX] = {0}; + char path_base[PATH_MAX] = {0}; + char path[PATH_MAX] = {0}; char *dir, *base; d->str_dup = realpath(some_path, NULL); if (!d->str_dup && errno == ENOENT) { - snprintf(path, sizeof path, "%s", some_path); - dir = dirname(path); + snprintf(path_dir, sizeof path_dir, "%s", some_path); + dir = dirname(path_dir); if (!dir) return 1; dir = realpath(dir, NULL); if (!dir) return 1; - snprintf(path, sizeof path, "%s", some_path); - base = basename(path); + + snprintf(path_base, sizeof path_base, "%s", some_path); + base = basename(path_base); if (!base) goto error; + snprintf(path, sizeof path, "%s/%s", dir, base); d->str_dup = strndup(path, strnlen(path, sizeof path)); error: diff --git a/src/utils.c b/src/utils.c index 71709f6..6911b07 100644 --- a/src/utils.c +++ b/src/utils.c @@ -977,7 +977,7 @@ int selftest_minimal_requirements(void) exit(EXIT_SUCCESS); } - s = open(getopt_str(OPT_ROFILE), O_WRONLY|O_CREAT|O_TRUNC); + s = open(getopt_str(OPT_ROFILE), O_WRONLY|O_CREAT|O_TRUNC, 0); if (s < 0 && errno != EEXIST) goto error; if (mkdir(getopt_str(OPT_RODIR), S_IRWXU) && errno != EEXIST) |