[gimp/gimp-2-10] plug-ins: do not use strcpy() when src and dest overlap.



commit 2484871cbc3eef548dd7b822f0e165382aa1e7c3
Author: Jehan <jehan girinstud io>
Date:   Sat Apr 4 00:32:07 2020 +0200

    plug-ins: do not use strcpy() when src and dest overlap.
    
    I don't reproduce these build warnings in my build but frogonia reported
    them:
    
    > warning: 'strcpy' accessing 1 byte at offsets 0 and [0, 2147483645] may overlap 1 byte at offset 0 
[-Wrestrict]
    
    And indeed the man of strcpy() clearly states that "The strings may not
    overlap" (which is clearly not guaranted in current code as we don't
    know the size of what's after the substring).
    strncpy() might have done the trick as it doesn't say anything about
    possible overlap or not, but let's just use memmove() instead where it
    is clearly written that memory areas may overlap (note that bcopy() as
    proposed by ankh would have also done the trick, but it is marked as
    deprecated).
    
    (cherry picked from commit 291af71e95e19714617f2c3cd3f6c434e9ca5408)

 plug-ins/metadata/metadata-editor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c
index 289fedc72f..fc958b700b 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -606,12 +606,12 @@ static void
 remove_substring (const gchar *string,
                   const gchar *substring)
 {
-  if (string != NULL && substring != NULL)
+  if (string != NULL && substring != NULL && substring[0] != '\0')
     {
       gchar *p = strstr (string, substring);
       if (p)
         {
-          strcpy (p, p + (gint) strlen (substring));
+          memmove (p, p + strlen (substring), strlen (p + strlen (substring)) + 1);
         }
     }
 }


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