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



commit 291af71e95e19714617f2c3cd3f6c434e9ca5408
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).

 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 8dd321f231..c92ce4f935 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -622,12 +622,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]