From 98c521793e28054722a8fc0007d4f68d28e94c51 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 6 Dec 2020 20:41:52 +0700 Subject: [PATCH] Fix potential NULL pointer dereferences --- source/compiler/memfile.c | 5 +++++ source/compiler/sclist.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/compiler/memfile.c b/source/compiler/memfile.c index 4307589..71fa50f 100644 --- a/source/compiler/memfile.c +++ b/source/compiler/memfile.c @@ -32,6 +32,11 @@ memfile_t *memfile_creat(const char *name, size_t init) mf.offs = 0; pmf = (memfile_t *)malloc(sizeof(memfile_t)); + if (!pmf) + { + free(mf.base); + return NULL; + } memcpy(pmf, &mf, sizeof(memfile_t)); pmf->name = strdup(name); diff --git a/source/compiler/sclist.c b/source/compiler/sclist.c index 516a276..f15ddd5 100644 --- a/source/compiler/sclist.c +++ b/source/compiler/sclist.c @@ -44,7 +44,8 @@ SC_FUNC char* duplicatestring(const char* sourcestring) { char* result=(char*)malloc(strlen(sourcestring)+1); - strcpy(result,sourcestring); + if (result!=NULL) + strcpy(result,sourcestring); return result; }