shadowsocks/ChinaDNS

Please Don't Compile With musl

Closed this issue · 5 comments

There is a bug in ns_skiprr function of musl, which make ns_initparse return -1 everytime.

int ns_skiprr(const unsigned char *ptr, const unsigned char *eom, ns_sect section, int count)
{
    const unsigned char *p = ptr;
    int r;

    while (count--) {
        r = dn_skipname(p, eom);
        if (r < 0) goto bad;
        if (r + 2 * NS_INT16SZ > eom - p) goto bad;
        p += r + 2 * NS_INT16SZ;
        if (section != ns_s_qd) {
            if (NS_INT32SZ + NS_INT16SZ > eom - p) goto bad;
            p += NS_INT32SZ;
            NS_GET16(r, p);
            if (r > eom - p) goto bad;
            p += r;
        }
    }
    return ptr - p; /*should be  p - ptr  */
bad:
    errno = EMSGSIZE;
    return -1;
}

If you want to compile ChinaDNS yourself, please compile with uclibc.
Otherwise, you need to create a patch and place it to toolchain/musl/patches.
The patch:

--- a/src/network/ns_parse.c
+++ b/src/network/ns_parse.c
@@ -95,7 +95,7 @@ int ns_skiprr(const unsigned char *ptr, const unsigned char *eom, ns_sect sectio
            p += r;
        }
    }
-   return ptr - p;
+   return p - ptr;
 bad:
    errno = EMSGSIZE;
    return -1;

thank you~ finally know the problem.

If you want to compile with musl-libc for OpenWrt, please update your codebase to openwrt-mirror/openwrt@365634d

@Pentiumluyu In my opinion, it's time to close this issue.