]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chfn: don't append extra tailing commas
authorKarel Zak <kzak@redhat.com>
Mon, 19 Aug 2019 12:03:07 +0000 (14:03 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 19 Aug 2019 12:03:07 +0000 (14:03 +0200)
 # grep kzak /etc/passwd
 kzak:x:1000:1000::/home/kzak:/bin/bash

 # chfn kzak
 ...
 grep kzak /etc/passwd

old version:
 kzak:x:1000:1000:Karel Zak,,,,:/home/kzak:/bin/bash

fixed version:
 kzak:x:1000:1000:Karel Zak:/home/kzak:/bin/bash

Reported-by: Filip Dvorak <fdvorak@redhat.com>
References: f723cbf544a7eac2927634f2cb6d802437a2d519
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/chfn.c

index a2e6e099e0fce484586301b0af5016fbc1f35a0e..b7395552bba90578fc74bf704f9b0d263ac6d30d 100644 (file)
@@ -376,7 +376,7 @@ static int save_new_data(struct chfn_control *ctl)
                        ctl->newf.other);
 
        /* remove trailing empty fields (but not subfields of ctl->newf.other) */
-       if (!ctl->newf.other) {
+       if (!ctl->newf.other || !*ctl->newf.other) {
                while (len > 0 && gecos[len - 1] == ',')
                        len--;
                gecos[len] = 0;