aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIoana Ciornei <ciorneiioana@gmail.com>2018-05-13 16:50:57 +0300
committerDmitry Vyukov <dvyukov@google.com>2018-05-13 16:27:22 +0200
commit481f030ccdc0fc0749f595c1f21b8c7c101387b2 (patch)
treea1841c618d3e8686dea44709d3b999c24a11bd62
parentd3a7c28ef14bbb9b17b85e6296555341a850f11f (diff)
executor: fix strncpy compile error
gcc8 is stricter when dealing with strings and strncpy and demands that the size of the actual string to be copied to be explicitly smaller than the size of the destination, just to make sure the NULL terminator is taken into considerantion. This patch fixes the issue. Signed-off-by: Ioana Ciornei <ciorneiioana@gmail.com>
-rw-r--r--executor/common_linux.h2
-rw-r--r--pkg/csource/linux_common.go2
2 files changed, 2 insertions, 2 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h
index 0b1f5c72a..45a74e36f 100644
--- a/executor/common_linux.h
+++ b/executor/common_linux.h
@@ -645,7 +645,7 @@ static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2)
// syz_open_dev(dev strconst, id intptr, flags flags[open_flags]) fd
char buf[1024];
char* hash;
- NONFAILING(strncpy(buf, (char*)a0, sizeof(buf)));
+ NONFAILING(strncpy(buf, (char*)a0, sizeof(buf) - 1));
buf[sizeof(buf) - 1] = 0;
while ((hash = strchr(buf, '#'))) {
*hash = '0' + (char)(a1 % 10); // 10 devices should be enough for everyone.
diff --git a/pkg/csource/linux_common.go b/pkg/csource/linux_common.go
index 06fc09137..77ba9b36f 100644
--- a/pkg/csource/linux_common.go
+++ b/pkg/csource/linux_common.go
@@ -765,7 +765,7 @@ static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2)
} else {
char buf[1024];
char* hash;
- NONFAILING(strncpy(buf, (char*)a0, sizeof(buf)));
+ NONFAILING(strncpy(buf, (char*)a0, sizeof(buf) - 1));
buf[sizeof(buf) - 1] = 0;
while ((hash = strchr(buf, '#'))) {
*hash = '0' + (char)(a1 % 10);