From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15845 invoked by alias); 15 Aug 2012 00:34:35 -0000 Received: (qmail 15587 invoked by uid 22791); 15 Aug 2012 00:34:34 -0000 X-SWARE-Spam-Status: No, hits=-5.5 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,TW_EG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-vc0-f169.google.com (HELO mail-vc0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Aug 2012 00:34:20 +0000 Received: by vcbfl10 with SMTP id fl10so1163565vcb.0 for ; Tue, 14 Aug 2012 17:34:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-system-of-record:x-gm-message-state; bh=U9DOdwoIDMDrpkssoU1kipQIP2XEL+HlucV8Yl5QYnM=; b=HCnLD/TfkQq81iVleNsEcTzsFqf8hvH/KmHuLamU41BgZLNGqd3glkF7zVankYds5o 65vmEE7qTJql/ABVH309i6jItqXqMB8olJygn5wXTzEEj4GE1iMOsnVuv9fEbmimWWxd cifnbcdQiA5PHZWii4YM3JvF4+sMAm8UIkVX2noTrP9W3nfW/Vh5EMQBHJoaQQZslSLx tzelOtrHyRLOpSBD3wEgWt25hkihsOtgmVVJKBCV76kaY4KZzuAe1ZursOufqXpZzQnG AQVsc5oJHJJ0SZOXTp7VloElrtrFLFji2MmYSHYPQG5RYKxSUaJWxDx/dnjp/mnVTljY 6eJw== Received: by 10.52.31.66 with SMTP id y2mr4798793vdh.122.1344990859758; Tue, 14 Aug 2012 17:34:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.31.66 with SMTP id y2mr4798787vdh.122.1344990859537; Tue, 14 Aug 2012 17:34:19 -0700 (PDT) Received: by 10.52.117.3 with HTTP; Tue, 14 Aug 2012 17:34:19 -0700 (PDT) In-Reply-To: References: Date: Wed, 15 Aug 2012 00:34:00 -0000 Message-ID: Subject: Re: [PATCH] gdb: trivial segfault fix in tui From: Doug Evans To: Hal Ashburner Cc: "Abid, Hafiz" , "gdb-patches@sourceware.org" Content-Type: text/plain; charset=ISO-8859-1 X-System-Of-Record: true X-Gm-Message-State: ALoCoQlv9Zw8FM7DiXWccRQDU8uUGbZCi2JQk1EkqYICF3+dzwSSU73qklfOl3phez1gBKpo7A5FJbx93PIYCN7lGPSZW8vii5Sq3SQQlb+EMa/PoSnQcZHpkrkcmAb8IPVsjjV2ITcW10FcDlp4OxbcIqpvqQmwWJrJkvL70KE3h9e4CPH92cDLN5tPeraBo+41eJN/lKR+gHaqs3FB4wwrhNjjy1hL2w== X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00423.txt.bz2 On Tue, Aug 14, 2012 at 4:03 PM, Hal Ashburner wrote: > Dear Hafiz, > > Thank you for letting me know this. > I've added a ChangeLog entry to the patch. I hope this is done the correct way. > > By way of trivia, I fixed this bug because I hit it more than once. > > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index 81c03ee..e1a080f 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,7 @@ > +2012-08-15 Hal Ashburner > + > + * tui/tui-source.c: Check for null pointer to prevent segfault. > + > 2012-08-10 Sergio Durigan Junior > > * linespec.c (find_methods): Remove unused variables `i1' and > diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c > index 9ba9b1d..0c94aed 100644 > --- a/gdb/tui/tui-source.c > +++ b/gdb/tui/tui-source.c > @@ -334,11 +334,13 @@ tui_show_symtab_source (struct gdbarch *gdbarch, > struct symtab *s, > int > tui_source_is_displayed (char *fname) > { > - return (TUI_SRC_WIN->generic.content_in_use > - && (filename_cmp (((struct tui_win_element *) > - (tui_locator_win_info_ptr ())-> > - content[0])->which_element.locator.file_name, > - fname) == 0)); > + if (tui_locator_win_info_ptr()->content) > + return (TUI_SRC_WIN->generic.content_in_use > + && (filename_cmp (((struct tui_win_element *) > + (tui_locator_win_info_ptr ())-> > + content[0])->which_element.locator.file_name, > + fname) == 0)); > + return 0; > } It seems tui is quite fragile with respect to window resizes. I was able to get a segv here for similar reasons, but I didn't write down the steps I did to trigger it. :-( tui-source.c: element->which_element.source.is_exec_point = (filename_cmp (((struct tui_win_element *) locator->content[0])->which_element.locator.file_name, s->filename) == 0 tui is also a bit, umm, weird. tui_free_window has this: generic_win = tui_locator_win_info_ptr (); if (generic_win != (struct tui_gen_win_info *) NULL) { tui_delete_win (generic_win->handle); generic_win->handle = (WINDOW *) NULL; } but tui_locator_win_info_ptr will never return NULL. struct tui_gen_win_info * tui_locator_win_info_ptr (void) { return &_locator; } Blech! In the end I suspect there's a better fix, but I don't know tui well enough. I'd wait to see if someone else does. Also, I'd add a comment explaining *why* the test for content != NULL, and I'd rewrite it as: return (TUI_SRC_WIN->generic.content_in_use && tui_locator_win_info_ptr()->content != NULL && ...); The style is more consistent this way.