st/nine: Fix reading invalid pointer
authorAxel Davy <davyaxel0@gmail.com>
Sun, 28 Mar 2021 16:30:40 +0000 (18:30 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 14 Apr 2021 08:33:13 +0000 (08:33 +0000)
Apparently it is incorrect to use the pointer in
LIST_FOR_EACH_ENTRY like I used to.
Found with asan.

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
Acked-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10160>

src/gallium/frontends/nine/nine_memory_helper.c

index ac9cde8..6cf1fda 100644 (file)
@@ -367,12 +367,13 @@ static void move_region_ordered(struct list_head *tail, struct nine_memfd_file_r
 
 static void move_region_ordered_merge(struct nine_allocator *allocator, struct list_head *tail, struct nine_memfd_file_region *region)
 {
-    struct nine_memfd_file_region *cur_region = NULL, *prev_region = NULL;
+    struct nine_memfd_file_region *p, *cur_region = NULL, *prev_region = NULL;
 
     /* Remove from previous list (if any) */
     list_delinit(&region->list);
 
-    LIST_FOR_EACH_ENTRY(cur_region, tail, list) {
+    LIST_FOR_EACH_ENTRY(p, tail, list) {
+        cur_region = p;
         if (cur_region->offset > region->offset)
             break;
         prev_region = cur_region;