public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch Darwin] minor fixups in section name reading.
@ 2011-12-08 14:18 Iain Sandoe
  2011-12-09  8:31 ` Tristan Gingold
  0 siblings, 1 reply; 4+ messages in thread
From: Iain Sandoe @ 2011-12-08 14:18 UTC (permalink / raw)
  To: binutils; +Cc: Tristan Gingold

[-- Attachment #1: Type: text/plain, Size: 436 bytes --]

this corrects a couple of trivial typos in  
bfd_mach_o_read_section_32/64.
It also caters for the fact that segment and section names may fill  
the on-disk field which is not zero-terminated.
So one cannot use them directly as strings.
OK?,
Iain


bfd:

	* mach-o.c (bfd_mach_o_make_bfd_section): Make strings from segname,  
sectname.
	(bfd_mach_o_read_section_32): Null-terminate sectname.
	(bfd_mach_o_read_section_64): Likewise.


[-- Attachment #2: 111207-macho-minor-secname-fixes-diff.txt --]
[-- Type: text/plain, Size: 1878 bytes --]

Index: bfd/mach-o.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.72
diff -u -p -r1.72 mach-o.c
--- bfd/mach-o.c	7 Dec 2011 10:09:22 -0000	1.72
+++ bfd/mach-o.c	8 Dec 2011 14:12:55 -0000
@@ -1667,9 +1667,16 @@ bfd_mach_o_make_bfd_section (bfd *abfd,
 {
   const char *sname;
   flagword flags;
+  char seg[BFD_MACH_O_SEGNAME_SIZE+1];
+  char sec[BFD_MACH_O_SECTNAME_SIZE+1];
+
+  memset (seg, 0, sizeof(seg));
+  strncpy (seg, (char *)segname, BFD_MACH_O_SEGNAME_SIZE);
+  memset (sec, 0, sizeof(sec));
+  strncpy (sec, (char *)sectname, BFD_MACH_O_SECTNAME_SIZE);
 
   bfd_mach_o_convert_section_name_to_bfd
-    (abfd, (const char *)segname, (const char *)sectname, &sname, &flags);
+    (abfd, (const char *)seg, (const char *)sec, &sname, &flags);
   if (sname == NULL)
     return NULL;
 
@@ -1698,7 +1705,7 @@ bfd_mach_o_read_section_32 (bfd *abfd,
   memcpy (section->segname, raw.segname, sizeof (raw.segname));
   section->segname[BFD_MACH_O_SEGNAME_SIZE] = 0;
   memcpy (section->sectname, raw.sectname, sizeof (raw.sectname));
-  section->segname[BFD_MACH_O_SECTNAME_SIZE] = 0;
+  section->sectname[BFD_MACH_O_SECTNAME_SIZE] = 0;
   section->addr = bfd_h_get_32 (abfd, raw.addr);
   section->size = bfd_h_get_32 (abfd, raw.size);
   section->offset = bfd_h_get_32 (abfd, raw.offset);
@@ -1737,7 +1744,7 @@ bfd_mach_o_read_section_64 (bfd *abfd,
   memcpy (section->segname, raw.segname, sizeof (raw.segname));
   section->segname[BFD_MACH_O_SEGNAME_SIZE] = 0;
   memcpy (section->sectname, raw.sectname, sizeof (raw.sectname));
-  section->segname[BFD_MACH_O_SECTNAME_SIZE] = 0;
+  section->sectname[BFD_MACH_O_SECTNAME_SIZE] = 0;
   section->addr = bfd_h_get_64 (abfd, raw.addr);
   section->size = bfd_h_get_64 (abfd, raw.size);
   section->offset = bfd_h_get_32 (abfd, raw.offset);

[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



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

* Re: [Patch Darwin] minor fixups in section name reading.
  2011-12-08 14:18 [Patch Darwin] minor fixups in section name reading Iain Sandoe
@ 2011-12-09  8:31 ` Tristan Gingold
  2011-12-09 10:01   ` Iain Sandoe
  0 siblings, 1 reply; 4+ messages in thread
From: Tristan Gingold @ 2011-12-09  8:31 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: binutils


On Dec 8, 2011, at 3:18 PM, Iain Sandoe wrote:

> this corrects a couple of trivial typos in bfd_mach_o_read_section_32/64.
> It also caters for the fact that segment and section names may fill the on-disk field which is not zero-terminated.
> So one cannot use them directly as strings.

Thank you for working on Mach-O.

See my comments.

(I think it is easier to review patches if they are inline).

Tristan.

> Index: bfd/mach-o.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/mach-o.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 mach-o.c
> --- bfd/mach-o.c	7 Dec 2011 10:09:22 -0000	1.72
> +++ bfd/mach-o.c	8 Dec 2011 14:12:55 -0000
> @@ -1667,9 +1667,16 @@ bfd_mach_o_make_bfd_section (bfd *abfd,
>  {
>    const char *sname;
>    flagword flags;
> +  char seg[BFD_MACH_O_SEGNAME_SIZE+1];
> +  char sec[BFD_MACH_O_SECTNAME_SIZE+1];
> +
> +  memset (seg, 0, sizeof(seg));
> +  strncpy (seg, (char *)segname, BFD_MACH_O_SEGNAME_SIZE);
> +  memset (sec, 0, sizeof(sec));
> +  strncpy (sec, (char *)sectname, BFD_MACH_O_SECTNAME_SIZE);
>  
>    bfd_mach_o_convert_section_name_to_bfd
> -    (abfd, (const char *)segname, (const char *)sectname, &sname, &flags);
> +    (abfd, (const char *)seg, (const char *)sec, &sname, &flags);
>    if (sname == NULL)
>      return NULL;

This is not necessary as bfd_mach_o_convert_section_name_to_bfd is documented as taking non nul terminated strings.  If there is a bug, it is in the later function.

> @@ -1698,7 +1705,7 @@ bfd_mach_o_read_section_32 (bfd *abfd,
>    memcpy (section->segname, raw.segname, sizeof (raw.segname));
>    section->segname[BFD_MACH_O_SEGNAME_SIZE] = 0;
>    memcpy (section->sectname, raw.sectname, sizeof (raw.sectname));
> -  section->segname[BFD_MACH_O_SECTNAME_SIZE] = 0;
> +  section->sectname[BFD_MACH_O_SECTNAME_SIZE] = 0;
>    section->addr = bfd_h_get_32 (abfd, raw.addr);
>    section->size = bfd_h_get_32 (abfd, raw.size);
>    section->offset = bfd_h_get_32 (abfd, raw.offset);
> @@ -1737,7 +1744,7 @@ bfd_mach_o_read_section_64 (bfd *abfd,
>    memcpy (section->segname, raw.segname, sizeof (raw.segname));
>    section->segname[BFD_MACH_O_SEGNAME_SIZE] = 0;
>    memcpy (section->sectname, raw.sectname, sizeof (raw.sectname));
> -  section->segname[BFD_MACH_O_SECTNAME_SIZE] = 0;
> +  section->sectname[BFD_MACH_O_SECTNAME_SIZE] = 0;
>    section->addr = bfd_h_get_64 (abfd, raw.addr);
>    section->size = bfd_h_get_64 (abfd, raw.size);
>    section->offset = bfd_h_get_32 (abfd, raw.offset);

Good catch.  You can commit this part.

Thanks,
Tristan.

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

* Re: [Patch Darwin] minor fixups in section name reading.
  2011-12-09  8:31 ` Tristan Gingold
@ 2011-12-09 10:01   ` Iain Sandoe
  2011-12-09 14:51     ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Iain Sandoe @ 2011-12-09 10:01 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils


On 9 Dec 2011, at 08:31, Tristan Gingold wrote:
>>
>>   section->size = bfd_h_get_64 (abfd, raw.size);
>>   section->offset = bfd_h_get_32 (abfd, raw.offset);
>
> Good catch.  You can commit this part.

My gcc.gnu.org user credentials appear to work for the checkout - but  
not for the commit.

Is there an additional procedure?
  (write access is not specifically mentioned on the binutils webpage).

thanks
Iain

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

* Re: [Patch Darwin] minor fixups in section name reading.
  2011-12-09 10:01   ` Iain Sandoe
@ 2011-12-09 14:51     ` Ian Lance Taylor
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2011-12-09 14:51 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Tristan Gingold, binutils

Iain Sandoe <developer@sandoe-acoustics.co.uk> writes:

> My gcc.gnu.org user credentials appear to work for the checkout - but
> not for the commit.
>
> Is there an additional procedure?
>  (write access is not specifically mentioned on the binutils webpage).

Having write access to gcc is not the same as having write access to the
binutils.  They are managed and granted separately.

Ian

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

end of thread, other threads:[~2011-12-09 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-08 14:18 [Patch Darwin] minor fixups in section name reading Iain Sandoe
2011-12-09  8:31 ` Tristan Gingold
2011-12-09 10:01   ` Iain Sandoe
2011-12-09 14:51     ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).