ld/PDB: fix off-by-1 in add_globals_ref()

Message ID 88c2fb96-185d-ae27-c025-ed025ed54641@suse.com
State Accepted
Headers
Series ld/PDB: fix off-by-1 in add_globals_ref() |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Jan Beulich July 7, 2023, 1:47 p.m. UTC
  Copying one too many bytes can corrupt memory, detected and reported by
glibc on a 32-bit distro.
---
Nick, again I expect this wants to go on the branch as well. I'm sorry
that I didn't get to look into this earlier; I had noticed it a while
ago already. In any event I'd like to give Mark a little bit of time
to reply (if necessary), before putting it in.
  

Comments

Mark Harmstone July 10, 2023, 11:30 p.m. UTC | #1
Thanks Jan - this looks good to me.

Mark

On 7/7/23 14:47, Jan Beulich wrote:
> Copying one too many bytes can corrupt memory, detected and reported by
> glibc on a 32-bit distro.
> ---
> Nick, again I expect this wants to go on the branch as well. I'm sorry
> that I didn't get to look into this earlier; I had noticed it a while
> ago already. In any event I'd like to give Mark a little bit of time
> to reply (if necessary), before putting it in.
>
> --- a/ld/pdb.c
> +++ b/ld/pdb.c
> @@ -880,7 +880,7 @@ add_globals_ref (struct globals *glob, b
>     g->offset = bfd_tell (sym_rec_stream);
>     g->hash = hash;
>     g->refcount = 1;
> -  memcpy (g->data, data, len + 1);
> +  memcpy (g->data, data, len);
>   
>     glob->num_entries++;
>
  
Jan Beulich July 12, 2023, 7:55 a.m. UTC | #2
On 11.07.2023 01:30, Mark Harmstone wrote:
> Thanks Jan - this looks good to me.

I've committed this yesterday, so Nick - what about cherry-picking it onto
the branch?

Jan

> On 7/7/23 14:47, Jan Beulich wrote:
>> Copying one too many bytes can corrupt memory, detected and reported by
>> glibc on a 32-bit distro.
>> ---
>> Nick, again I expect this wants to go on the branch as well. I'm sorry
>> that I didn't get to look into this earlier; I had noticed it a while
>> ago already. In any event I'd like to give Mark a little bit of time
>> to reply (if necessary), before putting it in.
>>
>> --- a/ld/pdb.c
>> +++ b/ld/pdb.c
>> @@ -880,7 +880,7 @@ add_globals_ref (struct globals *glob, b
>>     g->offset = bfd_tell (sym_rec_stream);
>>     g->hash = hash;
>>     g->refcount = 1;
>> -  memcpy (g->data, data, len + 1);
>> +  memcpy (g->data, data, len);
>>   
>>     glob->num_entries++;
>>   
> 
>
  
Nick Clifton July 17, 2023, 12:26 p.m. UTC | #3
Hi Jan,

> I've committed this yesterday, so Nick - what about cherry-picking it onto
> the branch?

Done.

Cheers
   Nick

PS.  Sorry for the delay - I have been on PTO.
  

Patch

--- a/ld/pdb.c
+++ b/ld/pdb.c
@@ -880,7 +880,7 @@  add_globals_ref (struct globals *glob, b
   g->offset = bfd_tell (sym_rec_stream);
   g->hash = hash;
   g->refcount = 1;
-  memcpy (g->data, data, len + 1);
+  memcpy (g->data, data, len);
 
   glob->num_entries++;