elinks/0020-elinks-0.15.0-static-analysis.patch
2022-04-11 10:07:07 +02:00

70 lines
1.6 KiB
Diff

From 0d49b8bf16b0ef992e331764ebae17d676115990 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Tue, 6 Nov 2018 18:35:19 +0100
Subject: [PATCH] elinks: fix programming mistakes detected by static analysis
---
src/intl/gettext/loadmsgcat.c | 13 +++++++++++--
src/scripting/lua/core.c | 8 ++++++--
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/intl/gettext/loadmsgcat.c b/src/intl/gettext/loadmsgcat.c
index 0d66152..5e62a5d 100644
--- a/src/intl/gettext/loadmsgcat.c
+++ b/src/intl/gettext/loadmsgcat.c
@@ -312,8 +312,10 @@ source_success:
char *read_ptr;
data = (struct mo_file_header *) malloc(size);
- if (data == NULL)
+ if (data == NULL) {
+ close(fd);
return;
+ }
to_read = size;
read_ptr = (char *) data;
@@ -346,8 +348,15 @@ source_success:
}
domain = (struct loaded_domain *) malloc(sizeof(struct loaded_domain));
- if (domain == NULL)
+ if (domain == NULL) {
+#ifdef LOADMSGCAT_USE_MMAP
+ if (use_mmap)
+ munmap((void *) data, size);
+ else
+#endif
+ free(data);
return;
+ }
domain_file->data = domain;
domain->data = (char *) data;
diff --git a/src/scripting/lua/core.c b/src/scripting/lua/core.c
index f0c9bc8..1c4636e 100644
--- a/src/scripting/lua/core.c
+++ b/src/scripting/lua/core.c
@@ -227,12 +227,16 @@ l_pipe_read(LS)
if (l > 0) {
char *news = mem_realloc(s, len + l);
- if (!news) goto lua_error;
+ if (!news) {
+ pclose(fp);
+ goto lua_error;
+ }
s = news;
memcpy(s + len, buf, l);
len += l;
- } else if (l < 0) {
+ } else {
+ pclose(fp);
goto lua_error;
}
}
--
2.34.1