From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6961 invoked by alias); 17 Aug 2010 00:31:24 -0000 Received: (qmail 6951 invoked by uid 22791); 17 Aug 2010 00:31:23 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,TW_BJ,TW_YY,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 17 Aug 2010 00:31:17 +0000 Received: from kpbe14.cbf.corp.google.com (kpbe14.cbf.corp.google.com [172.25.105.78]) by smtp-out.google.com with ESMTP id o7H0VF6g026034 for ; Mon, 16 Aug 2010 17:31:15 -0700 Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.18.118.116]) by kpbe14.cbf.corp.google.com with ESMTP id o7H0VE12029778 for ; Mon, 16 Aug 2010 17:31:14 -0700 Received: by ruffy.mtv.corp.google.com (Postfix, from userid 67641) id 087EA84B8F; Mon, 16 Aug 2010 17:31:13 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [patch] Handle 0 result from sscanf when parsing fp values. Message-Id: <20100817003114.087EA84B8F@ruffy.mtv.corp.google.com> Date: Tue, 17 Aug 2010 00:31:00 -0000 From: dje@google.com (Doug Evans) X-System-Of-Record: true 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: 2010-08/txt/msg00251.txt.bz2 Hi. I was getting an internal error from "p 0x1.1". (gdb) p 0x1.1 gdb/gdbtypes.c:1385: internal-error: check_typedef: Assertion `type' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. This is due to sscanf returning 0 and c-exp.y:parse_number not handling it. NOTE: Not all glibc's trigger this, and you have to do "p 0x1.1" first, otherwise the global yylval (c_lval) variable will just get reused, and no crash (or error!). I will commit the following in two days if there are no objections. NOTE: This patch uses gdb_assert_not_reached. ref: http://sourceware.org/ml/gdb-patches/2010-08/msg00250.html 2010-08-16 Doug Evans * c-exp.y (parse_number): Handle 0 result from sscanf. * objc-exp.y (parse_number): Ditto. testsuite/ * gdb.base/printcmds.exp (test_float_literals_rejected): New proc. Call it to test handling of bad floating point numbers. * gdb.objc/printcmds.exp: New file. Index: c-exp.y =================================================================== RCS file: /cvs/src/src/gdb/c-exp.y,v retrieving revision 1.76 diff -u -p -u -p -r1.76 c-exp.y --- c-exp.y 28 Jun 2010 20:18:26 -0000 1.76 +++ c-exp.y 17 Aug 2010 00:17:29 -0000 @@ -1371,12 +1371,18 @@ parse_number (char *p, int len, int pars &putithere->typed_val_float.dval, s); p[len] = saved_char; /* restore the input stream */ - if (num == 1) - putithere->typed_val_float.type = - parse_type->builtin_double; - - if (num == 2 ) + switch (num) { + case 0: + free (s); + return ERROR; + + case 1: + putithere->typed_val_float.type = + parse_type->builtin_double; + break; + + case 2: /* See if it has any float suffix: 'f' for float, 'l' for long double. */ if (!strcasecmp (s, "f")) @@ -1390,6 +1396,10 @@ parse_number (char *p, int len, int pars free (s); return ERROR; } + break; + + default: + gdb_assert_not_reached ("unexpected sscanf result"); } free (s); Index: objc-exp.y =================================================================== RCS file: /cvs/src/src/gdb/objc-exp.y,v retrieving revision 1.38 diff -u -p -u -p -r1.38 objc-exp.y --- objc-exp.y 5 Mar 2010 20:18:14 -0000 1.38 +++ objc-exp.y 17 Aug 2010 00:17:29 -0000 @@ -1016,8 +1016,9 @@ parse_number (p, len, parsed_float, puti /* It's a float since it contains a point or an exponent. */ - sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%c", - &putithere->typed_val_float.dval, &c); + if (sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%c", + &putithere->typed_val_float.dval, &c) != 1) + return ERROR; /* See if it has `f' or `l' suffix (float or long double). */ Index: testsuite/gdb.base/printcmds.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/printcmds.exp,v retrieving revision 1.35 diff -u -p -u -p -r1.35 printcmds.exp --- testsuite/gdb.base/printcmds.exp 21 Jul 2010 18:08:27 -0000 1.35 +++ testsuite/gdb.base/printcmds.exp 17 Aug 2010 00:17:29 -0000 @@ -146,6 +146,10 @@ proc test_integer_literals_rejected {} { test_print_reject "p 0b12" } +proc test_float_literals_rejected {} { + test_print_reject "p 0x1.1" +} + proc test_print_all_chars {} { global gdb_prompt @@ -794,6 +798,7 @@ if [set_lang_c] then { if [runto_main] then { test_integer_literals_accepted test_integer_literals_rejected + test_float_literals_rejected test_character_literals_accepted test_print_all_chars test_print_repeats_10 Index: testsuite/gdb.objc/printcmds.exp =================================================================== RCS file: testsuite/gdb.objc/printcmds.exp diff -N testsuite/gdb.objc/printcmds.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.objc/printcmds.exp 17 Aug 2010 00:17:29 -0000 @@ -0,0 +1,53 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2010 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Please email any bugs, comments, and/or additions to this file to: +# bug-gdb@gnu.org + +if $tracelevel { + strace $tracelevel +} + +# Set the current language to Objective-C. This counts as a test. If it +# fails, then we skip the other tests. + +proc set_lang_objc {} { + global gdb_prompt + + if [gdb_test_no_output "set language objective-c" "set language objective-c"] { + return 0 + } + + if [gdb_test "show language" ".* source language is \"objective-c\".*"] { + return 0 + } + return 1; +} + +proc test_float_literals_rejected {} { + test_print_reject "p 0x1.1" +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +if [set_lang_objc] { + test_float_literals_rejected +}