summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2016-07-20 13:16:13 +0200
committerKarel Zak2016-07-20 13:16:13 +0200
commit1132e5aad18cd3cf5326a4afa342fcd246d6aa6d (patch)
treef6c297dc6382703fb9798ffe762859846ea681aa
parentRevert "sfdisk: exit with error if rereading partition table fails" (diff)
downloadkernel-qcow2-util-linux-1132e5aad18cd3cf5326a4afa342fcd246d6aa6d.tar.gz
kernel-qcow2-util-linux-1132e5aad18cd3cf5326a4afa342fcd246d6aa6d.tar.xz
kernel-qcow2-util-linux-1132e5aad18cd3cf5326a4afa342fcd246d6aa6d.zip
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 <kzak@redhat.com>
-rw-r--r--term-utils/agetty.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index f3fc66714..3ad3612cd 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;
}