From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25008 invoked by alias); 28 Sep 2012 08:29:31 -0000 Received: (qmail 24992 invoked by uid 22791); 28 Sep 2012 08:29:28 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_CP X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 Sep 2012 08:29:18 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8S8TImb027264 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 28 Sep 2012 04:29:18 -0400 Received: from host2.jankratochvil.net (ovpn-116-94.ams2.redhat.com [10.36.116.94]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8S8TE1F005276 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 28 Sep 2012 04:29:16 -0400 Date: Fri, 28 Sep 2012 08:29:00 -0000 From: Jan Kratochvil To: Siddhesh Poyarekar Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] alpha: Use ssize_t to allocate space on stack Message-ID: <20120928082913.GB22720@host2.jankratochvil.net> References: <20120925210720.5c909379@spoyarek> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120925210720.5c909379@spoyarek> User-Agent: Mutt/1.5.21 (2010-09-15) 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-09/txt/msg00672.txt.bz2 On Tue, 25 Sep 2012 17:37:20 +0200, Siddhesh Poyarekar wrote: > --- gdb/alpha-tdep.c 25 Sep 2012 12:48:52 -0000 1.212 > +++ gdb/alpha-tdep.c 25 Sep 2012 15:21:46 -0000 > @@ -299,18 +299,18 @@ > { > enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); > int i; > - int accumulate_size = struct_return ? 8 : 0; > + ssize_t accumulate_size = struct_return ? 8 : 0; > struct alpha_arg > { > const gdb_byte *contents; > - int len; > - int offset; > + ssize_t len; > + ssize_t offset; > }; > struct alpha_arg *alpha_args > = (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg)); > struct alpha_arg *m_arg; > gdb_byte arg_reg_buffer[ALPHA_REGISTER_SIZE * ALPHA_NUM_ARG_REGS]; > - int required_arg_regs; > + ssize_t required_arg_regs; > CORE_ADDR func_addr = find_function_addr (function, NULL); > > /* The ABI places the address of the called function in T12. */ At line 409 is also code: m_arg->len = TYPE_LENGTH (arg_type); This is unsafe with extended TYPE_LENGTH width, because LONGEST > ssize_t. > @@ -414,6 +414,13 @@ > accumulate_size = 0; > else > accumulate_size -= sizeof(arg_reg_buffer); > + > + /* Check for underflow. */ > + if (sp - accumulate_size > sp) > + error (_("Insufficient memory in GDB host for arguments, " > + "need %s bytes, but less than %s bytes available."), > + plongest (accumulate_size), plongest (CORE_ADDR_MAX - sp)); > + > sp -= accumulate_size; > > /* Keep sp aligned to a multiple of 16 as the ABI requires. */ > @@ -423,8 +430,8 @@ > for (i = nargs; m_arg--, --i >= 0;) > { > const gdb_byte *contents = m_arg->contents; > - int offset = m_arg->offset; > - int len = m_arg->len; > + ssize_t offset = m_arg->offset; > + ssize_t len = m_arg->len; > > /* Copy the bytes destined for registers into arg_reg_buffer. */ > if (offset < sizeof(arg_reg_buffer)) > @@ -436,7 +443,7 @@ > } > else > { > - int tlen = sizeof(arg_reg_buffer) - offset; > + ssize_t tlen = sizeof(arg_reg_buffer) - offset; FYI this is not needed; but the code may be easier keeping it as you wrote it. > memcpy (arg_reg_buffer + offset, contents, tlen); > offset += tlen; > contents += tlen; Thanks, Jan