From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4F7C31F601 for ; Sat, 10 Dec 2022 02:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1670641118; bh=aTWQ4uXoWlJR7pepY+EKwX7FZmpbnAZLS8EV5qvd8dw=; h=Date:From:To:Subject:References:In-Reply-To:From; b=fKnXAcVchSZGDYl39STB9Jpf09nHD0637h0WGDvajTuNl6AVk+hj/mjLaxnb6jU7G HSpq7TnoX065LsavsXP282fGjr64lflV7PpR1Rd4gxKcmaJMRsoqG2SkCnudk1m8bF 4rl5u1nUhpw9XiKgWEh3DyygpT4+dKWqMJy0DoGI= Date: Sat, 10 Dec 2022 02:59:15 +0000 From: Eric Wong To: mwrap-perl@80x24.org Subject: Re: [PATCH 3/3] C-only HTTP Unix socket server + PSGI TCP reverse proxy Message-ID: <20221210025915.M446239@dcvr> References: <20221210015518.272576-1-e@80x24.org> <20221210015518.272576-4-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221210015518.272576-4-e@80x24.org> List-Id: Eric Wong wrote: > index 730699a..bed43d6 100644 > --- a/mwrap_core.h > +++ b/mwrap_core.h > +/* extract from backtrace_symbols(3) output */ > static int extract_addr(const char *str, size_t len, void **p) > { > - const char *c; > -#if defined(__GLIBC__) > - return ((c = memrchr(str, '[', len)) && sscanf(c, "[%p]", p)); > -#else /* TODO: test FreeBSD */ > - return ((c = strstr(str, "0x")) && sscanf(c, "%p", p)); > + unsigned long x; > + char *e; > +#if defined(__GLIBC__) /* str = "/path/to/foo.so(+0x123) [0xdeadbeefcafe]" */ > + const char *end = str + len; > + const char *c = memrchr(str, '[', len); > + if (c && (c + 2) < end && c[1] == '0' && c[2] == 'x') { > + errno = 0; > + x = strtoul(c + 3, &e, 16); > + if (!errno && *e == ']') { > + *p = (void *)x; > + return 1; > + } > + } > +#elif defined(__FreeBSD__) /* str = "0xdeadbeefcafe <%n%D> at %f" */ > + const char *c = memchr(str, ' ', len); > + errno = 0; > + if (len > 4 && c && str[0] == '0' && str[1] == 'x') { > + errno = 0; > + x = strtoul(str + 3, &e, 16); Erm, that should be `str + 2' on FreeBSD to skip "0x": diff --git a/mwrap_core.h b/mwrap_core.h index bed43d6..b2d0511 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -739,7 +739,7 @@ static int extract_addr(const char *str, size_t len, void **p) errno = 0; if (len > 4 && c && str[0] == '0' && str[1] == 'x') { errno = 0; - x = strtoul(str + 3, &e, 16); + x = strtoul(str + 2, &e, 16); if (!errno && *e == ' ') { *p = (void *)x; return 1;