Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-05-19 04:58:44 +0300
committerJunio C Hamano <gitster@pobox.com>2018-05-21 03:59:14 +0300
commitac4896f007a624c12feda866aeb4abe8a1394e39 (patch)
treeab584b8548ba953ac1110170bc117479add3dbdd /usage.c
parentbf4baf1fed7916ed10f2759a6f30a38990a83cae (diff)
fmt_with_err: add a comment that truncation is OK
Functions like die_errno() use fmt_with_err() to combine the caller-provided format with the strerror() string. We use a fixed stack buffer because we're already handling an error and don't have any way to report another one. Our buffer should generally be big enough to fit this, but if it's not, truncation is our best option. Let's add a comment to that effect, so that anybody auditing the code for truncation bugs knows that this is fine. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/usage.c b/usage.c
index cdd534c9df..b3c78931ad 100644
--- a/usage.c
+++ b/usage.c
@@ -148,6 +148,7 @@ static const char *fmt_with_err(char *buf, int n, const char *fmt)
}
}
str_error[j] = 0;
+ /* Truncation is acceptable here */
snprintf(buf, n, "%s: %s", fmt, str_error);
return buf;
}