aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnisse Astier <aastier@freebox.fr>2019-02-04 10:59:42 +0100
committerWill Deacon <will.deacon@arm.com>2019-02-08 16:04:07 +0000
commit96eda74100e9ffb1620cc0b9011e7e430b3d6ffb (patch)
treeeb04b58688a7cb58548947faa6ce010f5da28898
parent2f61a4427255c3debe7e0a56df838b21fbd00bc5 (diff)
downloadkvmtool-96eda74100e9ffb1620cc0b9011e7e430b3d6ffb.tar.gz
builtin-run: Fix warning when resolving path
GCC 8.2 gives this warning: builtin-run.c: In function ‘kvm_run_write_sandbox_cmd.isra.1’: builtin-run.c:417:28: error: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 4091 [-Werror=format-truncation=] snprintf(dst, len, "/host%s", resolved_path); ^~ ~~~~~~~~~~~~~ It's because it understands that len is PATH_MAX, the same as resolved_path's size. This patch handles the case where the string is truncated, and fixes the warning. Reviewed-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Anisse Astier <aastier@freebox.fr> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--builtin-run.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/builtin-run.c b/builtin-run.c
index 82e2b2e4..463a481f 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -414,7 +414,9 @@ static void resolve_program(const char *src, char *dst, size_t len)
if (!realpath(src, resolved_path))
die("Unable to resolve program %s: %s\n", src, strerror(errno));
- snprintf(dst, len, "/host%s", resolved_path);
+ if (snprintf(dst, len, "/host%s", resolved_path) >= (int)len)
+ die("Pathname too long: %s -> %s\n", src, resolved_path);
+
} else
strncpy(dst, src, len);
}