aports/community/txr/musl-crypt.patch
2023-11-11 22:56:37 +00:00

38 lines
1.3 KiB
Diff

Patch-Source: https://www.kylheku.com/lurker/message/20230903.185403.dbc73c46.en.html
--- a/sysif.c
+++ b/sysif.c
@@ -2081,9 +2081,18 @@ static val crypt_wrap(val wkey, val wsalt)
free(key);
free(salt);
- /* libxcrypt puts out two possible failure tokens "*0" or "*1".
+ /* libraries cannot agree on how to report unrecognized or bad hashes:
+ *
+ * - older glibc versions, other libraries return null
+ * - libxcrypt, integrated into newer glibc puts out two
+ * possible failure tokens "*0" or "*1", documenting
+ * that an error token starts with "*" and is less than 13
+ * characters long.
+ * - musl uses "*" and "x", the latter being in the valid hash charset!
+ *
+ * let's go with: null or less than 13 chars means error.
*/
- if (hash != 0 && strcmp(hash, "*0") != 0 && strcmp(hash, "*1") != 0) {
+ if (hash != 0 && memchr(hash, 0, 13) == 0) {
val ret = string_utf8(hash);
#if HAVE_CRYPT_R
free(cd);
--- a/tests/018/crypt.tl
+++ b/tests/018/crypt.tl
@@ -11,8 +11,7 @@
(if (eq :linux (os-symbol))
(mtest
(crypt "a" "b") :error
- (crypt "a" "$0$") :error
- (crypt "a" "$9$") :error
+ (crypt "a" "::") :error
(crypt "a" "$1$") "$1$$Ij31LCAysPM23KuPlm1wA/"
(crypt "a" "$1$bcd$") "$1$bcd$cgz778Ks3pkbWfyW.CWae/"
(crypt "a" "$5$") "$5$$QG6CCM7eJAxpUPcBpn0Z2K29NHtaI6Mk1fCpPrpjdj3"