From 66055dfe63c403e03c8f7e5b553d9c506cf11787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 6 May 2019 09:59:00 +0300 Subject: [PATCH] wrappers: Take the argv null terminator into account when checking for overflows When adding the terminator without incrementing arg and checking for overflows with "arg > max_arg", we need to allocate space for one extra element for the implicit terminator. --- wrappers/clang-target-wrapper.c | 2 +- wrappers/windres-wrapper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/clang-target-wrapper.c b/wrappers/clang-target-wrapper.c index 8f633a7..0f3779e 100644 --- a/wrappers/clang-target-wrapper.c +++ b/wrappers/clang-target-wrapper.c @@ -272,7 +272,7 @@ int _tmain(int argc, TCHAR* argv[]) { } int max_arg = argc + 20; - const TCHAR **exec_argv = malloc(max_arg * sizeof(*exec_argv)); + const TCHAR **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv)); int arg = 0; if (getenv("CCACHE")) exec_argv[arg++] = _T("ccache"); diff --git a/wrappers/windres-wrapper.c b/wrappers/windres-wrapper.c index a641fb7..dd07742 100644 --- a/wrappers/windres-wrapper.c +++ b/wrappers/windres-wrapper.c @@ -389,7 +389,7 @@ int _tmain(int argc, TCHAR* argv[]) { int max_arg = 2 * argc + 20; - const TCHAR **exec_argv = malloc(max_arg * sizeof(*exec_argv)); + const TCHAR **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv)); int arg = 0; if (!_tcscmp(input_format, _T("rc"))) {