Message ID | 3ad99625-43ff-a450-6e50-d83242224443@oracle.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 57918 invoked by alias); 6 Sep 2019 13:37:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 57910 invoked by uid 89); 6 Sep 2019 13:37:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Sep 2019 13:37:39 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x86DbPoI175700 for <gdb-patches@sourceware.org>; Fri, 6 Sep 2019 13:37:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : from : subject : message-id : date : mime-version : content-type; s=corp-2019-08-05; bh=uf+3U1Sb1XbfkvRPoeJRN0gTpr9PQ93ag+ZHc/RI/5M=; b=ebCTLt1sKY0Kdh1+ft2onbsDBhoR6celKFipcmDt4jN9BjIBgxkeBL4c0Wcv9jrOdwQe M+wC6hwhgVYYFpeiQb9AnNx3JE9e/ANnS+XnPqHe1gn5LrArbS+pgSfn4av5KZRuOa2I q+0cgrJUxtx8vzU1nSMuZEzPFsDrpgyssMpYgdJBYjveOfcMp4KYdlx20ar8m5+2xGTW Su+gHjGvK9aj6n+yEpTpFlZC08i/ZJMgJbJQ8ufkl4GtWaTdqvF5FqsL4z5LMM0bYNIq 4IwIQHNjZU+qJnS/BjAoFOsKZjxm1AjKXi3SHtGWJn9A0ToHz3QhXj3ibsFXmTdNsYRY /A== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2uur9dg2y3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <gdb-patches@sourceware.org>; Fri, 06 Sep 2019 13:37:37 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x86DXrgf098487 for <gdb-patches@sourceware.org>; Fri, 6 Sep 2019 13:37:36 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2uud7phesm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <gdb-patches@sourceware.org>; Fri, 06 Sep 2019 13:37:36 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x86DbZLe018938 for <gdb-patches@sourceware.org>; Fri, 6 Sep 2019 13:37:35 GMT Received: from [10.175.31.40] (/10.175.31.40) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 06 Sep 2019 06:37:35 -0700 To: gdb-patches@sourceware.org From: libor.bukata@oracle.com Subject: Fix a crash in compile_to_object function Message-ID: <3ad99625-43ff-a450-6e50-d83242224443@oracle.com> Date: Fri, 6 Sep 2019 15:37:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F4477BD7A4E1F5226327E098" X-IsSubscribed: yes |
Commit Message
libor.bukata@oracle.com
Sept. 6, 2019, 1:37 p.m. UTC
On non-Linux platforms, gdb crashes when compile command is issued because of the null pointer in struct osabi_names gdb_osab. The attached patch adds a check to avoid this crash and adds osabi name for Solaris. However, there is probably more work required to enable compile feature on Solaris (e.g., solaris_infcall_munmap) and other platforms. Thanks, Libor
Comments
On 9/6/19 6:37 AM, libor.bukata@oracle.com wrote: > On non-Linux platforms, gdb crashes when compile command is issued > because of the null pointer in struct osabi_names gdb_osab. The attached > patch adds a check to avoid this crash and adds osabi name for Solaris. > However, there is probably more work required to enable compile feature > on Solaris (e.g., solaris_infcall_munmap) and other platforms. > Thank you for the patch! The compile feature, as you have discovered, needs much more testing on non-linux configurations. > --- gdb-8.3/gdb/compile/compile.c 2019-08-19 13:07:57.669785758 +0000 > +++ gdb-8.3/gdb/compile/compile.c 2019-08-19 13:07:33.865626973 +0000 > @@ -697,7 +697,7 @@ compile_to_object (struct command_line * > const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); > > /* Allow triplets with or without vendor set. */ > - triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx; > + triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + (os_rx ? : ""); > compiler->set_triplet_regexp (triplet_rx.c_str ()); > } I'm not sure about this. Should os_rx be NULL (which you've shown is possible for a number of configurations), this would leave triplet_rx as $ARCH(-[^-]*)?-", e.g., "x86_64(-[^-]*)?-". I would call that a malformed regexp for this purpose. While the plugin may handle that gracefully, this just doesn't seem very user-friendly to me, but I am not a maintainer, so you should definitely wait for a real maintainer to chime in. Otherwise, the only comments I have relate to > + triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + (os_rx ? : ""); We prefer explicit comparisons with NULL/nullptr. Omitting the true-case expression is unusual. Not invalid, but certainly unusual (in gdb). I find no uses of this idiom in our sources. I would prefer to see the more explicit os_rx != nullptr ? os_rx : "" but I'll let official maintainers chime in on this usage. I'm just as curious to see how others feel about it. Keith
Hi Keith, I have no objections to use 'os_rx != NULL ? os_rx : ""' instead; it is more portable. Note that NULL should be used instead of nullptr as nullptr is available since C++11. Thanks, Libor feel free to use 'os_rx != nullptr ? os_rx : ""' instead On 9/6/19 6:42 PM, Keith Seitz wrote: > On 9/6/19 6:37 AM, libor.bukata@oracle.com wrote: >> On non-Linux platforms, gdb crashes when compile command is issued >> because of the null pointer in struct osabi_names gdb_osab. The attached >> patch adds a check to avoid this crash and adds osabi name for Solaris. >> However, there is probably more work required to enable compile feature >> on Solaris (e.g., solaris_infcall_munmap) and other platforms. >> > Thank you for the patch! The compile feature, as you have discovered, needs > much more testing on non-linux configurations. > >> --- gdb-8.3/gdb/compile/compile.c 2019-08-19 13:07:57.669785758 +0000 >> +++ gdb-8.3/gdb/compile/compile.c 2019-08-19 13:07:33.865626973 +0000 >> @@ -697,7 +697,7 @@ compile_to_object (struct command_line * >> const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); >> >> /* Allow triplets with or without vendor set. */ >> - triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx; >> + triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + (os_rx ? : ""); >> compiler->set_triplet_regexp (triplet_rx.c_str ()); >> } > I'm not sure about this. Should os_rx be NULL (which you've shown is possible > for a number of configurations), this would leave triplet_rx as $ARCH(-[^-]*)?-", > e.g., "x86_64(-[^-]*)?-". I would call that a malformed regexp for this purpose. > > While the plugin may handle that gracefully, this just doesn't seem very > user-friendly to me, but I am not a maintainer, so you should definitely > wait for a real maintainer to chime in. > > Otherwise, the only comments I have relate to > >> + triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + (os_rx ? : ""); > We prefer explicit comparisons with NULL/nullptr. > > Omitting the true-case expression is unusual. Not invalid, but certainly > unusual (in gdb). I find no uses of this idiom in our sources. I would > prefer to see the more explicit > > os_rx != nullptr ? os_rx : "" > > but I'll let official maintainers chime in on this usage. I'm just as curious > to see how others feel about it. > > Keith
Hi Libor, > On non-Linux platforms, gdb crashes when compile command is issued > because of the null pointer in struct osabi_names gdb_osab. The attached > patch adds a check to avoid this crash and adds osabi name for Solaris. > However, there is probably more work required to enable compile feature > on Solaris (e.g., solaris_infcall_munmap) and other platforms. just out of curiosity: what prompted you to try this? I gave it a very quick whirl myself, trying to run the gdb.compile/compile.exp test on amd64-pc-solaris2.11 with gdb master and libcc1.so from gcc mainline: all I got was a SIGTRAP from the very first compile command. That said, I'm quite unlikely to work on this any time soon: with ca. 2500 failures in the gdb testsuite on Solaris and even basic features unimplented (e.g. I'm currently looking into TLS support), I believe there are way more pressing issues. However, if you want to give it a try yourself, I'm more than happy to help get a patch in. Rainer
Hi Rainer, I noticed it from the testsuite results (crash dump generated) for gdb 8.3. Although it is not implemented for Solaris, it should not crash, which is the reason why I sent a patch that resolves a nullptr dereference. The patched gdb prints an error message (instead of crashing) and the user can continue with debugging. I agree with you that there many more pressing issues that needs to be resolved first. Thanks, Libor On 9/9/19 10:07 AM, Rainer Orth wrote: > Hi Libor, > >> On non-Linux platforms, gdb crashes when compile command is issued >> because of the null pointer in struct osabi_names gdb_osab. The attached >> patch adds a check to avoid this crash and adds osabi name for Solaris. >> However, there is probably more work required to enable compile feature >> on Solaris (e.g., solaris_infcall_munmap) and other platforms. > just out of curiosity: what prompted you to try this? > > I gave it a very quick whirl myself, trying to run the > gdb.compile/compile.exp test on amd64-pc-solaris2.11 with gdb master and > libcc1.so from gcc mainline: all I got was a SIGTRAP from the very first > compile command. > > That said, I'm quite unlikely to work on this any time soon: with > ca. 2500 failures in the gdb testsuite on Solaris and even basic > features unimplented (e.g. I'm currently looking into TLS support), I > believe there are way more pressing issues. However, if you want to > give it a try yourself, I'm more than happy to help get a patch in. > > Rainer >
>>>>> ">" == libor bukata <libor.bukata@oracle.com> writes: >> I have no objections to use 'os_rx != NULL ? os_rx : ""' instead; it >> is more portable. Note that NULL should be used instead of nullptr as >> nullptr is available since C++11. Just FYI, gdb uses C++11 nowadays, so nullptr is fine. Tom
Hi Libor, > I noticed it from the testsuite results (crash dump generated) for gdb > 8.3. Although it is not implemented for Solaris, it should not crash, which > is the reason why I sent a patch that resolves a nullptr dereference. The > patched gdb prints an error message (instead of crashing) and the user can > continue with debugging. I agree with you that there many more pressing > issues that needs to be resolved first. that explains why I'm not seeing this in my gdb builds: I use a 32-bit-default gcc 9.1 to build a 64-bit gdb, so there's no matching libcc1.so around and the affected tests are UNTESTED. Fully agreed that there should be no crashes even for unsupported features, of course. I'll leave the actual review to the responsible maintainers. Rainer
The patch fixes the crash on non-Linux platforms when os_rx is a null pointer and converted to C++ std::string. --- gdb-8.3/gdb/osabi.c 2019-08-19 11:15:04.176948730 +0000 +++ gdb-8.3/gdb/osabi.c 2019-08-19 11:13:43.202284584 +0000 @@ -63,7 +63,7 @@ static const struct osabi_names gdb_osab { "SVR4", NULL }, { "GNU/Hurd", NULL }, - { "Solaris", NULL }, + { "Solaris", "solaris[2-9]\.[0-9][0-9]" }, { "GNU/Linux", "linux(-gnu[^-]*)?" }, { "FreeBSD", NULL }, { "NetBSD", NULL }, --- gdb-8.3/gdb/compile/compile.c 2019-08-19 13:07:57.669785758 +0000 +++ gdb-8.3/gdb/compile/compile.c 2019-08-19 13:07:33.865626973 +0000 @@ -697,7 +697,7 @@ compile_to_object (struct command_line * const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); /* Allow triplets with or without vendor set. */ - triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx; + triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + (os_rx ? : ""); compiler->set_triplet_regexp (triplet_rx.c_str ()); }