Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] bfd/coff-ppc.c: Be sure of zero terminated string after copy from '_n_name'
@ 2014-08-06 15:52 Chen Gang
  2014-08-07  1:52 ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Chen Gang @ 2014-08-06 15:52 UTC (permalink / raw)
  To: amodra, hjl.tools, nickc; +Cc: binutils, gdb-patches

'_n_name' may not be zero terminated string, and it may copy to 'name'
or 'my_name' which are assumed that must be zero terminated string. So
during copy operation, need be sure of them zero terminated.

Also remove the usless asignment to 'name'.

2014-08-06  Chen Gang <gang.chen.5i5j@gmail.com>

	* coff-ppc.c (coff_ppc_relocate_section): Be sure of zero
	terminatedstring after copy from '_n_name'.

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 bfd/coff-ppc.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/bfd/coff-ppc.c b/bfd/coff-ppc.c
index 3c39afa..318a220 100644
--- a/bfd/coff-ppc.c
+++ b/bfd/coff-ppc.c
@@ -1073,10 +1073,11 @@ coff_ppc_relocate_section (bfd *output_bfd,
 	      {
 		/* It is a file local symbol.  */
 		int *local_toc_table;
-		const char *name;
+		char name[SYMNMLEN + 1];
 
 		sym = syms + symndx;
-		name = sym->_n._n_name;
+		strncpy (name, sym->_n._n_name, SYMNMLEN);
+		name[SYMNMLEN] = '\0';
 
 		local_toc_table = obj_coff_local_toc_table(input_bfd);
 		our_toc_offset = local_toc_table[symndx];
@@ -1225,9 +1226,14 @@ coff_ppc_relocate_section (bfd *output_bfd,
 	case IMAGE_REL_PPC_ABSOLUTE:
 	  {
 	    const char *my_name;
+	    char buf[SYMNMLEN + 1];
 
 	    if (h == 0)
-	      my_name = (syms+symndx)->_n._n_name;
+	      {
+		strncpy (buf, (syms+symndx)->_n._n_name, SYMNMLEN);
+		buf[SYMNMLEN] = '\0';
+		my_name = buf;
+	      }
 	    else
 	      my_name = h->root.root.root.string;
 
@@ -1288,11 +1294,8 @@ coff_ppc_relocate_section (bfd *output_bfd,
 	      }
 
 	    if (h == 0)
-	      {
 		/* It is a file local symbol.  */
 		sym = syms + symndx;
-		name = sym->_n._n_name;
-	      }
 	    else
 	      {
 		char *target = 0;
-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bfd/coff-ppc.c: Be sure of zero terminated string after copy from '_n_name'
  2014-08-06 15:52 [PATCH] bfd/coff-ppc.c: Be sure of zero terminated string after copy from '_n_name' Chen Gang
@ 2014-08-07  1:52 ` Alan Modra
  2014-08-07  4:56   ` Chen Gang
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2014-08-07  1:52 UTC (permalink / raw)
  To: Chen Gang; +Cc: hjl.tools, nickc, binutils, gdb-patches

On Wed, Aug 06, 2014 at 11:52:31PM +0800, Chen Gang wrote:
> '_n_name' may not be zero terminated string, and it may copy to 'name'
> or 'my_name' which are assumed that must be zero terminated string. So
> during copy operation, need be sure of them zero terminated.
> 
> Also remove the usless asignment to 'name'.
> 
> 2014-08-06  Chen Gang <gang.chen.5i5j@gmail.com>
> 
> 	* coff-ppc.c (coff_ppc_relocate_section): Be sure of zero
> 	terminatedstring after copy from '_n_name'.

This is OK.

-- 
Alan Modra
Australia Development Lab, IBM


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bfd/coff-ppc.c: Be sure of zero terminated string after copy from '_n_name'
  2014-08-07  1:52 ` Alan Modra
@ 2014-08-07  4:56   ` Chen Gang
  2014-08-07  6:15     ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Chen Gang @ 2014-08-07  4:56 UTC (permalink / raw)
  To: hjl.tools, nickc, binutils, gdb-patches

On 08/07/2014 09:51 AM, Alan Modra wrote:
> On Wed, Aug 06, 2014 at 11:52:31PM +0800, Chen Gang wrote:
>> '_n_name' may not be zero terminated string, and it may copy to 'name'
>> or 'my_name' which are assumed that must be zero terminated string. So
>> during copy operation, need be sure of them zero terminated.
>>
>> Also remove the usless asignment to 'name'.
>>
>> 2014-08-06  Chen Gang <gang.chen.5i5j@gmail.com>
>>
>> 	* coff-ppc.c (coff_ppc_relocate_section): Be sure of zero
>> 	terminatedstring after copy from '_n_name'.
> 
> This is OK.
> 

Excuse me, my English is not quite well, I don't quite understand your
meaning, I guess your meaning is: "This patch is OK to you, if no any
objections next, it can be applied by the related maintainers".

If what I guess is incorrect, please let me know.

Thanks.
-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bfd/coff-ppc.c: Be sure of zero terminated string after copy from '_n_name'
  2014-08-07  4:56   ` Chen Gang
@ 2014-08-07  6:15     ` Alan Modra
  2014-08-07  9:06       ` Chen Gang
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2014-08-07  6:15 UTC (permalink / raw)
  To: Chen Gang; +Cc: hjl.tools, nickc, binutils, gdb-patches

On Thu, Aug 07, 2014 at 12:56:34PM +0800, Chen Gang wrote:
> On 08/07/2014 09:51 AM, Alan Modra wrote:
> > On Wed, Aug 06, 2014 at 11:52:31PM +0800, Chen Gang wrote:
> >> '_n_name' may not be zero terminated string, and it may copy to 'name'
> >> or 'my_name' which are assumed that must be zero terminated string. So
> >> during copy operation, need be sure of them zero terminated.
> >>
> >> Also remove the usless asignment to 'name'.
> >>
> >> 2014-08-06  Chen Gang <gang.chen.5i5j@gmail.com>
> >>
> >> 	* coff-ppc.c (coff_ppc_relocate_section): Be sure of zero
> >> 	terminatedstring after copy from '_n_name'.
> > 
> > This is OK.
> > 
> 
> Excuse me, my English is not quite well, I don't quite understand your
> meaning, I guess your meaning is: "This patch is OK to you, if no any
> objections next, it can be applied by the related maintainers".

I meant, the patch is OK for you to commit, but I guess you don't have
commit rights.  I've committed the patch for you.  Thanks!

-- 
Alan Modra
Australia Development Lab, IBM


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bfd/coff-ppc.c: Be sure of zero terminated string after copy from '_n_name'
  2014-08-07  6:15     ` Alan Modra
@ 2014-08-07  9:06       ` Chen Gang
  0 siblings, 0 replies; 5+ messages in thread
From: Chen Gang @ 2014-08-07  9:06 UTC (permalink / raw)
  To: hjl.tools, nickc, binutils, gdb-patches

On 08/07/2014 02:15 PM, Alan Modra wrote:
> On Thu, Aug 07, 2014 at 12:56:34PM +0800, Chen Gang wrote:
>> On 08/07/2014 09:51 AM, Alan Modra wrote:
>>> On Wed, Aug 06, 2014 at 11:52:31PM +0800, Chen Gang wrote:
>>>> '_n_name' may not be zero terminated string, and it may copy to 'name'
>>>> or 'my_name' which are assumed that must be zero terminated string. So
>>>> during copy operation, need be sure of them zero terminated.
>>>>
>>>> Also remove the usless asignment to 'name'.
>>>>
>>>> 2014-08-06  Chen Gang <gang.chen.5i5j@gmail.com>
>>>>
>>>> 	* coff-ppc.c (coff_ppc_relocate_section): Be sure of zero
>>>> 	terminatedstring after copy from '_n_name'.
>>>
>>> This is OK.
>>>
>>
>> Excuse me, my English is not quite well, I don't quite understand your
>> meaning, I guess your meaning is: "This patch is OK to you, if no any
>> objections next, it can be applied by the related maintainers".
> 
> I meant, the patch is OK for you to commit, but I guess you don't have
> commit rights.  I've committed the patch for you.  Thanks!
> 

OK, thank you for your explanation and your work. And I shall continue
to try to send another patch for binutils within this month.

Thanks.
-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-07  9:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-06 15:52 [PATCH] bfd/coff-ppc.c: Be sure of zero terminated string after copy from '_n_name' Chen Gang
2014-08-07  1:52 ` Alan Modra
2014-08-07  4:56   ` Chen Gang
2014-08-07  6:15     ` Alan Modra
2014-08-07  9:06       ` Chen Gang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox