dfu: Fix possible wrong memory access 32/229032/1
authorDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 27 Mar 2020 07:11:44 +0000 (16:11 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 27 Mar 2020 07:13:30 +0000 (16:13 +0900)
Currently, dfu context is assigned after thread creation, tfm can
be died due to wrong memory access if thread is scheduled in advance.
This fixes this by assigning ctx before thread creation.

Change-Id: I44f86223b90d6dac537699369a478d4cdb7829c2
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/dfu.c

index acb8887..c33c286 100644 (file)
--- a/src/dfu.c
+++ b/src/dfu.c
@@ -400,13 +400,12 @@ struct dfu_entry *dfu_start(struct dfu_context *ctx,
                return NULL;
        }
 
-       pthread_create(&ctx->thread, NULL, dfu_thread_main, e);
-
-       e->ctx = ctx;
-
        fprintf(stdout, "Start download: %s...", filename);
        fflush(stdout);
 
+       e->ctx = ctx;
+       pthread_create(&ctx->thread, NULL, dfu_thread_main, e);
+
        return e;
 }