From 7b838007abe626fe8dfa72e53f54b55b679f026b Mon Sep 17 00:00:00 2001 From: suve Date: Thu, 3 Dec 2020 13:45:03 +0100 Subject: [PATCH] Use "%.*s" when printing VERSION Commit 7bb2fef0e244220cc3f0f1dfc4317297f158b943 attempted to fix the "missing NUL-terminator in VERSION" issue by replacing the "%s" conversion specifier with "%*s". However, this fix itself was wrong, as "%*s" specifies the field width, i.e. _minimum_ number of characters to print. The proper solution is to use "%.*s", which specifies the precision, i.e. the _maximum_ number of printed characters. --- dumb-init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dumb-init.c b/dumb-init.c index 6cdd2c7..9c40637 100644 --- a/dumb-init.c +++ b/dumb-init.c @@ -126,7 +126,7 @@ void handle_signal(int signum) { void print_help(char *argv[]) { fprintf(stderr, - "dumb-init v%*s" + "dumb-init v%.*s" "Usage: %s [option] command [[arg] ...]\n" "\n" "dumb-init is a simple process supervisor that forwards signals to children.\n" @@ -199,7 +199,7 @@ char **parse_command(int argc, char *argv[]) { debug = 1; break; case 'V': - fprintf(stderr, "dumb-init v%*s", VERSION_len, VERSION); + fprintf(stderr, "dumb-init v%.*s", VERSION_len, VERSION); exit(0); case 'c': use_setsid = 0;