From: Karel Zak Date: Wed, 20 Jul 2016 11:16:13 +0000 (+0200) Subject: agetty: fix \S usage X-Git-Tag: v2.29-rc1~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1132e5aad18cd3cf5326a4afa342fcd246d6aa6d;p=thirdparty%2Futil-linux.git agetty: fix \S usage If \S without argument used then uninitialized 'varname' compared with ANSI_COLOR. Addresses: https://github.com/karelzak/util-linux/issues/329 Signed-off-by: Karel Zak --- diff --git a/term-utils/agetty.c b/term-utils/agetty.c index f3fc66714c..3ad3612cd4 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -2446,17 +2446,22 @@ static void output_special_char(unsigned char c, struct options *op, { char *var = NULL, varname[64]; - if (get_escape_argument(fp, varname, sizeof(varname))) + /* \S{varname} */ + if (get_escape_argument(fp, varname, sizeof(varname))) { var = read_os_release(op, varname); - else if (!(var = read_os_release(op, "PRETTY_NAME"))) - var = uts.sysname; - if (var) { - if (strcmp(varname, "ANSI_COLOR") == 0) - printf("\033[%sm", var); - else - printf("%s", var); - if (var != uts.sysname) - free(var); + if (var) { + if (strcmp(varname, "ANSI_COLOR") == 0) + printf("\033[%sm", var); + else + fputs(var, stdout); + } + /* \S */ + } else if ((var = read_os_release(op, "PRETTY_NAME"))) { + fputs(var, stdout); + + /* \S and PRETTY_NAME not found */ + } else { + fputs(uts.sysname, stdout); } break; }