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 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

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 Files:

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

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

    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.3