Skip to content

Commit

Permalink
NUL-terminate gai->value for OPT_RESOLVE, fix out-of-bound read
Browse files Browse the repository at this point in the history
Signed-off-by: Youfu Zhang <zhangyoufu@gmail.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
  • Loading branch information
zhangyoufu authored and dwmw2 committed May 12, 2017
1 parent a01a167 commit 539e3ee
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.c
Expand Up @@ -1174,15 +1174,15 @@ int main(int argc, char **argv)
fprintf(stderr, _("Missing colon in resolve option\n"));
exit(1);
}
gai = malloc(sizeof(*gai) + strlen(config_arg));
gai = malloc(sizeof(*gai) + strlen(config_arg) + 1);
if (!gai) {
fprintf(stderr, _("Failed to allocate memory\n"));
exit(1);
}
gai->next = gai_overrides;
gai_overrides = gai;
gai->option = (void *)(gai + 1);
memcpy(gai->option, config_arg, strlen(config_arg));
memcpy(gai->option, config_arg, strlen(config_arg) + 1);
gai->option[ip - config_arg] = 0;
gai->value = gai->option + (ip - config_arg) + 1;
break;
Expand Down

0 comments on commit 539e3ee

Please sign in to comment.