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

 
 

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

Submitter:  Maarten ter Huurne <maartenth>
Submitted:  Mon 15 Sep 2014 02:03:54 AM UTC
   
 
Category:  Program Logic Severity:  3 - Normal
Priority:  * 5 - Normal Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Release:  4.2.1
Fixed Release:  None Planned Release:  None
Work Required:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

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>

 

Attached Files

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

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

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

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

    Votes

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    History

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-09-15 maartenth Attached 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.16-ed84.
    Corresponding source code