diff options
author | Ondřej Surý <ondrej.sury@nic.cz> | 2017-02-08 13:23:07 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej.sury@nic.cz> | 2017-02-08 13:23:07 +0100 |
commit | 46d87c85afff68252b929c0f25c619b6864ab39e (patch) | |
tree | 9d9762dcb5728d001257335835d3f9e77c17e090 /daemon/main.c | |
parent | Merge branch 'add_libedit_2' into 'master' (diff) | |
parent | Fix -k argument processing to avoid out-of-bounds memory accesses (diff) | |
download | knot-resolver-46d87c85afff68252b929c0f25c619b6864ab39e.tar.xz knot-resolver-46d87c85afff68252b929c0f25c619b6864ab39e.zip |
Merge branch 'k_param' into 'master'
Fix -k argument processing to avoid out-of-bounds memory accesses
See merge request !195
Diffstat (limited to 'daemon/main.c')
-rw-r--r-- | daemon/main.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/daemon/main.c b/daemon/main.c index 0e0ed01c..3624787f 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -676,17 +676,18 @@ int main(int argc, char **argv) char *_filename = basename(basename_storage); int dirlen = strlen(keyfile_dir); int namelen = strlen(_filename); - if (dirlen + namelen >= PATH_MAX) { + if (dirlen + 1 + namelen >= PATH_MAX) { kr_log_error("[ ta ]: keyfile '%s' PATH_MAX exceeded\n", keyfile); ret = EXIT_FAILURE; goto cleanup; } - keyfile_dir[dirlen] = '/'; + keyfile_dir[dirlen++] = '/'; + keyfile_dir[dirlen] = '\0'; auto_free char *keyfile_path = malloc(dirlen + namelen + 1); - memcpy(keyfile_path, keyfile_dir, dirlen + 1); - memcpy(keyfile_path + dirlen + 1, _filename, namelen + 1); + memcpy(keyfile_path, keyfile_dir, dirlen); + memcpy(keyfile_path + dirlen, _filename, namelen + 1); int unmanaged = 0; |