[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 4/5] crypt_make_salt(): fixup odd calling convention
From:       Rasmus Villemoes <rasmus.villemoes () prevas ! dk>
Date:       2024-04-15 12:56:27
Message-ID: 20240415125628.780178-5-rasmus.villemoes () prevas ! dk
[Download RAW message or body]

Due to the implementation of crypt_make_salt(), it used to make sense
that the length parameter was only half of the expected length of the
salt, but that's not so any more, so clean it up and make the callers
pass the desired length directly.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 libbb/pw_encrypt.c | 8 +++-----
 networking/httpd.c | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c
index 9ac75b281..3de31f711 100644
--- a/libbb/pw_encrypt.c
+++ b/libbb/pw_encrypt.c
@@ -37,8 +37,6 @@ static int i64c(int i)
 int FAST_FUNC crypt_make_salt(char *p, int cnt)
 {
 	unsigned x = getpid() + monotonic_us();
-	/* Odd calling convention... */
-	cnt *= 2;
 	do {
 		*p++ = i64c(x);
 		x >>= 6;
@@ -49,21 +47,21 @@ int FAST_FUNC crypt_make_salt(char *p, int cnt)
 
 char* FAST_FUNC crypt_make_pw_salt(char salt[MAX_PW_SALT_LEN], const char *algo)
 {
-	int len = 2/2;
+	int len = 2;
 	char *salt_ptr = salt;
 
 	/* Standard chpasswd uses uppercase algos ("MD5", not "md5").
 	 * Need to be case-insensitive in the code below.
 	 */
 	if ((algo[0]|0x20) != 'd') { /* not des */
-		len = 8/2; /* so far assuming md5 */
+		len = 8; /* so far assuming md5 */
 		*salt_ptr++ = '$';
 		*salt_ptr++ = '1';
 		*salt_ptr++ = '$';
 #if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA
 		if ((algo[0]|0x20) == 's') { /* sha */
 			salt[1] = '5' + (strcasecmp(algo, "sha512") == 0);
-			len = 16/2;
+			len = 16;
 		}
 #endif
 	}
diff --git a/networking/httpd.c b/networking/httpd.c
index ddcb03bca..825a87d81 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2826,7 +2826,7 @@ int httpd_main(int argc UNUSED_PARAM, char **argv)
 		salt[0] = '$';
 		salt[1] = '1';
 		salt[2] = '$';
-		crypt_make_salt(salt + 3, 4);
+		crypt_make_salt(salt + 3, 8);
 		puts(pw_encrypt(pass, salt, /*cleanup:*/ 0));
 		return 0;
 	}
-- 
2.40.1.1.g1c60b9335d

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic