From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9453 invoked by alias); 29 Apr 2018 16:18:11 -0000 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 Received: (qmail 9395 invoked by uid 89); 29 Apr 2018 16:18:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=corner, UD:gnu-ifunc.exp, gnuifuncexp, gnu-ifunc.exp X-HELO: mail-yb0-f171.google.com Received: from mail-yb0-f171.google.com (HELO mail-yb0-f171.google.com) (209.85.213.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 29 Apr 2018 16:18:04 +0000 Received: by mail-yb0-f171.google.com with SMTP id r13-v6so2311169ybm.12 for ; Sun, 29 Apr 2018 09:18:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=owmPjQwCBeekEB7VUp1lm5VTTRiefPTPbPYlJ5KxhgY=; b=S1pW/fJy9qPm0viEzxTVXXqtW9DgvvHx46d7JE5vqE9LRjNeVfyf7m89Fn4iCOwfL0 4UUnnib3SlnPOr7f+qNk7JcngERz7uLK1X32bRSN4Gpt3NKEAgeikcL7+bNkyYRaJ1Xg VdehIDuyUzO4LvPc4OwsSaLnG24WhrGXslyGEec3GAMtnqxRUPk4eWLPKXVc3OdClnez T8sTY7FAKVn4Gftj9ljBOokKdW7tUuib8baPtAwDOV5vv282skHzJJI2qt5sNH+gkfUR tIX4ikdNHrsC8mbPDW8UnguaK//ux128yJ46FNJLvBVj8AhSrjdUaHY2B6ru8qyeAVFn K8TA== X-Gm-Message-State: ALQs6tCo2WjoVm7tTe2VHLDtpM40uRw7U7I8lA/8/hLihtXltnAN5DdY Be74t9KklxP3DZ2n/5YFHBgdvA== X-Google-Smtp-Source: AB8JxZo8s6RDpOzHE2WQqACeL+eBnqLZe595Iy1GHeVW8BRqp4CCOssjYj9a5ocqaSwF1y1EAqPDnw== X-Received: by 2002:a25:1f55:: with SMTP id f82-v6mr5157892ybf.111.1525018683175; Sun, 29 Apr 2018 09:18:03 -0700 (PDT) Received: from tomyris ([2601:c2:c100:d169:5ab2:4b40:897c:82a9]) by smtp.gmail.com with ESMTPSA id p184-v6sm2509494ywh.91.2018.04.29.09.18.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Apr 2018 09:18:01 -0700 (PDT) Date: Sun, 29 Apr 2018 16:18:00 -0000 From: Dan Robertson To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] bug 23124: rust - Fix null deref when casting Message-ID: <20180429161452.GA19936@tomyris> References: <20180428032443.GA1869@tomyris> <87fu3e7jtp.fsf@tromey.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="eJnRUKwClWJh1Khz" Content-Disposition: inline In-Reply-To: <87fu3e7jtp.fsf@tromey.com> User-Agent: Mutt/1.9.5 (2018-04-13) X-SW-Source: 2018-04/txt/msg00603.txt.bz2 --eJnRUKwClWJh1Khz Content-Type: multipart/mixed; boundary="opJtzjQTFsWo+cga" Content-Disposition: inline --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 262 Thanks for the critiques! Attached an updated patch. Added the minimal repro listed in the bug and a simple function pointer example to gdb.rust/expr.exp. I also added ChangeLog entries and updated the change to align with the gdb code standards. Cheers, Dan --opJtzjQTFsWo+cga Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-rust-Fix-null-deref-when-casting-PR-23124.patch" Content-Transfer-Encoding: quoted-printable Content-length: 2659 =46rom e20401ca99c82ac4b0cf39e87b4771388360a211 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Sat, 28 Apr 2018 03:18:00 +0000 Subject: [PATCH] rust: Fix null deref when casting (PR 23124) Fix a null dereference when casting a value to a unit type. --- gdb/ChangeLog | 6 ++++++ gdb/rust-exp.y | 7 +++++-- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.rust/expr.exp | 4 +++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cd86be7fb3..102d54b442 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-04-28 Dan Robertson + + PR rust/23124 + * gdb/rust-exp.y (convert_params_to_types): Ensure that the params pointer + is not null before dereferencing it. + 2018-04-26 Andrzej Kaczmarek =20 PR remote/9665 diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index b661a803e3..865959f7d9 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -2007,8 +2007,11 @@ convert_params_to_types (struct parser_state *state,= rust_op_vector *params) { std::vector result; =20 - for (const rust_op *op : *params) - result.push_back (convert_ast_to_type (state, op)); + if (params !=3D nullptr) + { + for (const rust_op *op : *params) + result.push_back (convert_ast_to_type (state, op)); + } =20 return result; } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 34da102c62..c52fa15335 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-04-28 Dan Robertson + + PR rust/23124 + * gdb.rust/expr.exp: Test that the unit type is correctly parsed + when casting. + 2018-04-26 Pedro Alves =20 * gdb.base/gnu-ifunc.exp (set-break): Test that GDB resolves diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.= exp index 0bc0630854..22e6b49b54 100644 --- a/gdb/testsuite/gdb.rust/expr.exp +++ b/gdb/testsuite/gdb.rust/expr.exp @@ -133,7 +133,9 @@ gdb_test "print \[23usize; 4\]" " =3D \\\[23, 23, 23, 2= 3\\\]" gdb_test "ptype \[23usize; 4\]" " =3D \\\[usize; 4\\\]" gdb_test "print \[mut 23usize; 4\]" " =3D \\\[23, 23, 23, 23\\\]" =20 -# Test a lexer corner case. +# Test lexer corner cases. +gdb_test "print 0x0 as *const ()" " =3D \\\(\\\(\\\) \\*\\\) 0x0" +gdb_test "print 0x0 as fn(i64) -> ()" " =3D \\\(\\\(\\\) \\\(\\*\\\)\\\(i6= 4\\\)\\\) 0x0" gdb_test "print r#" "syntax error in expression, near `#'\\." =20 gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22" --=20 2.17.0 --opJtzjQTFsWo+cga-- --eJnRUKwClWJh1Khz Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEF5dO2RaKc5C+SCJ9RcSmUsR+QqUFAlrl73wACgkQRcSmUsR+ QqWPMQ//Wd8OlTNCAUPL4NjBPYe2gJqMVmG9VoTTpdly90XsQS06JOOdKTFzVAer Siv3aB4iVYZQJpGPwgQFdQPvZey7IKwJUzaMlOl7+7/47lfCMyz4v9+j3sJMkIKf J030K0eQS7YD2jofaSpEL/Hw4ymNvr9R+xiX3NxyubSixUcBobsBabPBV/tu0fok YH7VkudXz3S3VXcztNIO6KTTFEQjlLNMNpnpHx8pYLLwy+oI7aK/fJOvYcrHJktv JyP0TBwUyOWYPbncx4wwgHMlQ30LD5RNlHCHHrieDTFX0tWWZ8bunhCzohT5DCMG XhtzBkAXteLidOQkoIpxKVp2jPqlnzojbmLs89H3ZiFoPF/plkOcKPEnxzKzOrj0 OWC/bBqOTQ69RMt+GDLXT5rUH8zDijRuye5KAdReLQEqPdpFUaKexn7DwcXdhn6p VHECouHsGLHrASL0dPEZWEhEPmNdOJkErZMYj0WnAZQMYNCettB/Hwis0XPcOuys xX/2pcp9Z/gfad2P+uBwKnh9UAaK4z4fyXAEkvrZqHAo23dH20BZMtXf50J50v1b kzSQ5yUcbiDFAXCTuC/VEqG50OiaJ+odSCJfZsEtsq3GSsdxrU/GOTEx/EzOJniU fFux2H98jT6E3PDw7uncCAe5dXEZ+CLd4RAih4fgIpAAhgqYNG0= =Gm/T -----END PGP SIGNATURE----- --eJnRUKwClWJh1Khz--