bugGNU Screen - Bugs: bug #43222, memcpy is not a safe fallback for...

 
 

bug #43222: memcpy is not a safe fallback for bcopy/memmove

Submitted by:  Maarten ter Huurne <maartenth>
Submitted on:  Mon 15 Sep 2014 02:03:54 AM UTC  
 
Category: Program LogicSeverity: 3 - Normal
Priority: 5 - NormalStatus: None
Privacy: PublicAssigned to: None
Open/Closed: OpenRelease: 4.2.1
Fixed Release: NonePlanned Release: None
Work Required: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon 15 Sep 2014 02:03:54 AM UTC, original submission:

Screen tries 4 alternatives for handing memory copies that potentially overlap, in this order:
- bcopy from libc
- memmove
- memcpy
- bcopy from Screen (xbcopy)

However, memcpy is not a safe alternative, since its behavior when the memory regions overlap is explicitly left undefined by the specification. The configure script tries to work around that by testing the behavior of memcpy on overlapping memory, but if the test passes that doesn't provide any guarantee that other overlapping regions will also be copied correctly. This is not just a theoretical concern: memcpy implementations can have different code paths depending on pointer alignment and size of the block to be copied and this test would only excercise a single code path.

In practice systems with broken bcopy/memmove will be rare these days, so most systems will not be affected. But for those where a fallback is necessary, it is best to fall back on Screen's own bcopy, which might be slower but is at least reliable.

I attached a patch that removes memcpy as a fallback.

Maarten ter Huurne <maartenth>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #32096:  0001-Do-not-use-memcpy-as-an-alternative-for-bcopy-memmov.patch added by maartenth (3KiB - application/octet-stream - git formatted patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by maartenth (Submitted the item)
  • -unavailable- added by maartenth
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 15 Sep 2014 02:03:54 AM UTCmaartenthAttached File-=>Added 0001-Do-not-use-memcpy-as-an-alternative-for-bcopy-memmov.patch, #32096
      Carbon-Copy-=>Added maartenth

    Back to the top


    Powered by Savane 3.1-cleanup1