The current password checking is unable to distinguish between the user
entering an empty password or pressing Control-D. As a result, an empty
password always results in normal startup.

We modify bb_ask to store the EOF status after the null terminator if
the password is empty. This allows sulogin to properly check if
Control-D was pressed.

Signed-off-by: Jonathan Liu <[email protected]>
---
 libbb/bb_askpass.c   | 3 +++
 loginutils/sulogin.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c
index fe2b506..4df0901 100644
--- a/libbb/bb_askpass.c
+++ b/libbb/bb_askpass.c
@@ -75,6 +75,9 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char 
*prompt)
                 || ++i == sizeof_passwd-1 /* line limit */
                ) {
                        ret[i] = '\0';
+                       /* if empty, store EOF status after null terminator */
+                       if (i == 0)
+                               ret[i + 1] = (r == 0);
                        break;
                }
        }
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index bd2b09e..9fcf530 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -84,7 +84,7 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
                                "Give root password for system maintenance\n"
                                "(or type Control-D for normal startup):");
 
-               if (!cp || !*cp) {
+               if (!cp || (!*cp && cp[1])) {
                        bb_info_msg("Normal startup");
                        return 0;
                }
-- 
1.8.2.3

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to