libbb: move nuke_str() from passwd into libbb
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 19 Nov 2013 12:36:45 +0000 (13:36 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 19 Nov 2013 12:36:45 +0000 (13:36 +0100)
function                                             old     new   delta
nuke_str                                               -      15     +15
ask_and_check_password_extended                      215     206      -9
init_main                                            781     771     -10
nuke_str                                              27       -     -27
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 15/-46)            Total: -31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
include/libbb.h
init/init.c
libbb/correct_password.c
loginutils/passwd.c

index e99bb92..64167bb 100644 (file)
@@ -1300,9 +1300,10 @@ int sd_listen_fds(void);
 #define SETUP_ENV_CLEARENV  (1 << 1)
 #define SETUP_ENV_TO_TMP    (1 << 2)
 #define SETUP_ENV_NO_CHDIR  (1 << 4)
-extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
-extern int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
-extern int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
+void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
+void nuke_str(char *str) FAST_FUNC;
+int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
+int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
 /* Returns a malloced string */
 #if !ENABLE_USE_BB_CRYPT
 #define pw_encrypt(clear, salt, cleanup) pw_encrypt(clear, salt)
index 2dcdfd4..c63bba1 100644 (file)
@@ -1128,7 +1128,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
        strncpy(argv[0], "init", strlen(argv[0]));
        /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
        while (*++argv)
-               memset(*argv, 0, strlen(*argv));
+               nuke_str(*argv);
 
        /* Set up signal handlers */
        if (!DEBUG_INIT) {
index d39a583..5727c65 100644 (file)
 
 #include "libbb.h"
 
+void FAST_FUNC nuke_str(char *str)
+{
+        if (str) {
+               while (*str)
+                       *str++ = 0;
+               /* or: memset(str, 0, strlen(str)); - not as small as above */
+       }
+}
+
 /* Ask the user for a password.
  * Return 1 without asking if PW has an empty password.
  * Return -1 on EOF, error while reading input, or timeout.
@@ -76,7 +85,7 @@ int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw,
        encrypted = pw_encrypt(unencrypted, correct, 1);
        r = (strcmp(encrypted, correct) == 0);
        free(encrypted);
-       memset(unencrypted, 0, strlen(unencrypted));
+       nuke_str(unencrypted);
        return r;
 }
 
index a7006f0..1509089 100644 (file)
 #include <syslog.h>
 #include <sys/resource.h> /* setrlimit */
 
-static void nuke_str(char *str)
-{
-       if (str) memset(str, 0, strlen(str));
-}
-
 static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo)
 {
        char salt[MAX_PW_SALT_LEN];