@@ -31,8 +31,49 @@ MUSL=musl-1.2.3
3131if [ ! -d $MUSL ]; then
3232 curl https://www.musl-libc.org/releases/$MUSL .tar.gz | tar xzf -
3333fi
34-
3534cd $MUSL
35+
36+ # Apply patches for CVE-2025-26519. At the time of adding these patches no release containing them
37+ # has been published by the musl project, so we just apply them directly on top of the version we
38+ # were distributing already. The patches should be removed once we upgrade to musl >= 1.2.6.
39+ #
40+ # Advisory: https://www.openwall.com/lists/musl/2025/02/13/1
41+ #
42+ # Patches applied:
43+ # - https://www.openwall.com/lists/musl/2025/02/13/1/1
44+ # - https://www.openwall.com/lists/musl/2025/02/13/1/2
45+ #
46+ # ignore-tidy-tab
47+ # ignore-tidy-linelength
48+ patch -p1 << EOF
49+ --- a/src/locale/iconv.c
50+ +++ b/src/locale/iconv.c
51+ @@ -502,7 +502,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
52+ if (c >= 93 || d >= 94) {
53+ c += (0xa1-0x81);
54+ d += 0xa1;
55+ - if (c >= 93 || c>=0xc6-0x81 && d>0x52)
56+ + if (c > 0xc6-0x81 || c==0xc6-0x81 && d>0x52)
57+ goto ilseq;
58+ if (d-'A'<26) d = d-'A';
59+ else if (d-'a'<26) d = d-'a'+26;
60+ EOF
61+ patch -p1 << EOF
62+ --- a/src/locale/iconv.c
63+ +++ b/src/locale/iconv.c
64+ @@ -545,6 +545,10 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
65+ if (*outb < k) goto toobig;
66+ memcpy(*out, tmp, k);
67+ } else k = wctomb_utf8(*out, c);
68+ + /* This failure condition should be unreachable, but
69+ + * is included to prevent decoder bugs from translating
70+ + * into advancement outside the output buffer range. */
71+ + if (k>4) goto ilseq;
72+ *out += k;
73+ *outb -= k;
74+ break;
75+ EOF
76+
3677./configure --enable-debug --disable-shared --prefix=/musl-$TAG " $@ "
3778if [ " $TAG " = " i586" -o " $TAG " = " i686" ]; then
3879 hide_output make -j$( nproc) AR=ar RANLIB=ranlib
0 commit comments