screen-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[screen-devel] [bug #43222] memcpy is not a safe fallback for bcopy/memm


From: Maarten ter Huurne
Subject: [screen-devel] [bug #43222] memcpy is not a safe fallback for bcopy/memmove
Date: Mon, 15 Sep 2014 02:03:55 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) konqueror/4.14.0 Safari/537.21

URL:
  <http://savannah.gnu.org/bugs/?43222>

                 Summary: memcpy is not a safe fallback for bcopy/memmove
                 Project: GNU Screen
            Submitted by: maartenth
            Submitted on: Mon 15 Sep 2014 02:03:54 AM GMT
                Category: Program Logic
                Severity: 3 - Normal
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.2.1
           Fixed Release: None
         Planned Release: None
           Work Required: None

    _______________________________________________________

Details:

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.



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Mon 15 Sep 2014 02:03:54 AM GMT  Name:
0001-Do-not-use-memcpy-as-an-alternative-for-bcopy-memmov.patch  Size: 3kB  
By: maartenth
git formatted patch
<http://savannah.gnu.org/bugs/download.php?file_id=32096>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?43222>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]