checkpatch: Do not allow deprecated g_memdup()
authorPhilippe Mathieu-Daudé <philmd@redhat.com>
Fri, 3 Sep 2021 17:45:10 +0000 (19:45 +0200)
committerLaurent Vivier <laurent@vivier.eu>
Fri, 17 Dec 2021 10:57:35 +0000 (11:57 +0100)
g_memdup() is insecure and as been deprecated in GLib 2.68.
QEMU provides the safely equivalent g_memdup2() wrapper.

Do not allow more g_memdup() calls in the repository, provide
a hint to use g_memdup2().

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210903174510.751630-29-philmd@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
scripts/checkpatch.pl

index cb8eff233e0656e8d64344e2325467cb8671f114..5caa739db4866b9ae559db20ba369b59eb71cc1b 100755 (executable)
@@ -2850,6 +2850,11 @@ sub process {
                        WARN("consider using g_path_get_$1() in preference to g_strdup($1())\n" . $herecurr);
                }
 
+# enforce g_memdup2() over g_memdup()
+               if ($line =~ /\bg_memdup\s*\(/) {
+                       ERROR("use g_memdup2() instead of unsafe g_memdup()\n" . $herecurr);
+               }
+
 # recommend qemu_strto* over strto* for numeric conversions
                if ($line =~ /\b(strto[^kd].*?)\s*\(/) {
                        ERROR("consider using qemu_$1 in preference to $1\n" . $herecurr);