From 2ddf19764d9f1ddb8beae80d85ce64eedceb9aa4 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Sat, 1 Feb 2020 18:24:23 +0100 Subject: [PATCH] handle partial read files, avoid crashes (AFL) --- camlibs/spca50x/library.c | 5 ++++- camlibs/spca50x/spca50x-sdram.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/camlibs/spca50x/library.c b/camlibs/spca50x/library.c index 37487cb8c..93de246b7 100644 --- a/camlibs/spca50x/library.c +++ b/camlibs/spca50x/library.c @@ -330,7 +330,10 @@ file_list_func (CameraFilesystem *fs, const char *folder, CHECK (spca50x_sdram_get_info (camera->pl)); for (i = 0; i < camera->pl->num_files_on_sdram; i++) { - strncpy (temp_file, camera->pl->files[i].name, 12); + if (camera->pl->files[i].name) + strncpy (temp_file, camera->pl->files[i].name, 12); + else + strcpy (temp_file, "BAD.BAD"); temp_file[12] = 0; gp_list_append (list, temp_file, NULL); } diff --git a/camlibs/spca50x/spca50x-sdram.c b/camlibs/spca50x/spca50x-sdram.c index f11cc8a32..7a2900008 100644 --- a/camlibs/spca50x/spca50x-sdram.c +++ b/camlibs/spca50x/spca50x-sdram.c @@ -226,6 +226,7 @@ spca50x_get_image (CameraPrivateLibrary * lib, uint8_t ** buf, int omit_escape = 0; p = g_file->fat; + if (!p) return GP_ERROR; /* get the position in memory where the image is */ start = (p[1] & 0xff) + (p[2] & 0xff) * 0x100;