Subject: Bug#1005942: adduser: spews error when ^Ding out of binary question, proceeds anyway

From: наб <[email-masked]>
Date: Thu, 17 Feb 2022 16:50:23 +0100

Package: adduser
Version: 3.118
Severity: normal
Tags: patch

Dear Maintainer,

adduser asks two binary questions: about retrying passwd and about
retrying chfn.

If you ^D out of them, currently, you get this:
-- >8 --
nabijaczleweli@tarta:~$ sudo adduser dupsko12
Adding user `dupsko12' ...
Adding new group `dupsko12' (1019) ...
Adding new user `dupsko12' (1022) with group `dupsko12' ...
Creating home directory `/home/dupsko12' ...
Copying files from `/etc/skel' ...
New password: ^D
Password change has been aborted.
passwd: Authentication token manipulation error
passwd: password unchanged
Try again? [y/N] ^D Use of uninitialized value $answer in chop at /usr/sbin/adduser line 556.
Use of uninitialized value $answer in pattern match (m//) at /usr/sbin/adduser line 557.
Changing the user information for dupsko12
Enter the new value, or press ENTER for the default
        Full Name []: ^D   Room Number []:         Work Phone []:  Home Phone []:  Other []: Is the information correct? [Y/n] ^D Use of uninitialized value $answer in chop at /usr/sbin/adduser line 582.
Use of uninitialized value $answer in pattern match (m//) at /usr/sbin/adduser line 583.

nabijaczleweli@tarta:~$ grep dupsko12 /etc/passwd
dupsko12:x:1022:1019:,,,:/home/dupsko12:/bin/bash
-- >8 --

Proceeding through an error spew is suboptimal,
but keeping the current behaviour would be nice.

Please consider the patch below
(based on current Salsa, i.e. a7c40dcd86aefe6b4d6fa926a8101222dc1bad01),
which falls through to the default answer (as already happens)
without the error spew:
-- >8 --
nabijaczleweli@tarta:~/uwu/adduser$ sudo ./adduser dupsko10
Adding user `dupsko10' ...
Adding new group `dupsko10' (1017) ...
Adding new user `dupsko10' (1020) with group `dupsko10' ...
Creating home directory `/home/dupsko10' ...
Copying files from `/etc/skel' ...
New password: ^D
Password change has been aborted.
passwd: Authentication token manipulation error
passwd: password unchanged
Try again? [y/N] ^D Changing the user information for dupsko10
Enter the new value, or press ENTER for the default
        Full Name []: ^D   Room Number []:         Work Phone []:  Home Phone []:  Other []: Is the information correct? [Y/n] ^D nabijaczleweli@tarta:~/uwu/adduser$

nabijaczleweli@tarta:~/uwu/adduser$ grep dupsko10 /etc/passwd
dupsko10:x:1020:1017:,,,:/home/dupsko10:/bin/bash
-- >8 --

Best,
наб

-- System Information:
Debian Release: 11.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable-debug'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.10.0-11-amd64 (SMP w/24 CPU threads)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_FIRMWARE_WORKAROUND, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages adduser depends on:
ii  debconf [debconf-2.0]  1.5.77
ii  passwd                 1:4.8.1-1

adduser recommends no packages.

Versions of packages adduser suggests:
ii  liblocale-gettext-perl  1.07-4+b1
ii  perl                    5.32.1-4+deb11u2

-- debconf information:
  adduser/title:
  adduser/homedir-permission: true
From f30cdc4697001a2069a4f700fe7fed6583950a35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <[email-masked]>
Date: Thu, 17 Feb 2022 16:41:55 +0100
Subject: [PATCH] adduser: default to default binary action when ^D out of
 prompts instead of spewing an error but proceeding
X-Mutt-PGP: OS

---
 adduser | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/adduser b/adduser
index 2fb54ec..411c203 100755
--- a/adduser
+++ b/adduser
@@ -537,7 +537,8 @@ if ($action eq "adduser") {
 	    # locale.  You can see by running "locale noexpr" which regular
 	    # expression will be checked to find positive answer.
 	    print (gtx("Try again? [y/N] "));
-	    chop ($answer=<STDIN>);
+	    defined ($answer=<STDIN>) or $answer = "";
+	    chop ($answer);
 	    last if ($answer !~ m/$yesexpr/o);
 	  }
 	  else {
@@ -563,7 +564,9 @@ if ($action eq "adduser") {
 	    # locale.  You can see by running "locale yesexpr" which regular
 	    # expression will be checked to find positive answer.
 	    print (gtx("Is the information correct? [Y/n] "));
-	    chop (my $answer=<STDIN>);
+	    my $answer=<STDIN>;
+	    defined ($answer) or $answer = "";
+	    chop ($answer);
 	    last if ($answer !~ m/$noexpr/o);
 	}
     }
-- 
2.30.2