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

Add a New Comment Rich Markup
   

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 Files:
   
   
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
  • -email is unavailable- added by maartenth (Submitted the item)
  • -email is unavailable- added by maartenth
  •  

    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.

     

    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.13-f8d8.
    Corresponding source code