Ai
12 Star 0 Fork 16

src-openEuler/checkpolicy
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-checkpolicy-cleanup-resources-on-parse-error.patch 2.35 KB
一键复制 编辑 原始数据 按行查看 历史
wjiang 提交于 2025-03-14 14:45 +08:00 . backport patches from upstream
From c2fc48be68ee466207d870137681896b0b544691 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Mon, 22 Jan 2024 14:54:54 +0100
Subject: [PATCH] checkpolicy: cleanup resources on parse error
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Close the input file and free all memory by the queue and lexer on a
syntax or parse error.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
---
parse_util.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/parse_util.c b/parse_util.c
index 8c1f393..5f92730 100644
--- a/parse_util.c
+++ b/parse_util.c
@@ -26,6 +26,7 @@ extern FILE *yyin;
extern void init_parser(int);
extern int yyparse(void);
extern void yyrestart(FILE *);
+extern int yylex_destroy(void);
extern queue_t id_queue;
extern unsigned int policydb_errors;
extern policydb_t *policydbp;
@@ -34,6 +35,8 @@ extern void set_source_file(const char *name);
int read_source_policy(policydb_t * p, const char *file, const char *progname)
{
+ int rc = -1;
+
yyin = fopen(file, "r");
if (!yyin) {
fprintf(stderr, "%s: unable to open %s: %s\n", progname, file, strerror(errno));
@@ -41,21 +44,26 @@ int read_source_policy(policydb_t * p, const char *file, const char *progname)
}
set_source_file(file);
- if ((id_queue = queue_create()) == NULL) {
+ id_queue = queue_create();
+ if (id_queue == NULL) {
fprintf(stderr, "%s: out of memory!\n", progname);
- return -1;
+ goto cleanup;
}
+ mlspol = p->mls;
policydbp = p;
policydbp->name = strdup(file);
- mlspol = p->mls;
+ if (!policydbp->name) {
+ fprintf(stderr, "%s: out of memory!\n", progname);
+ goto cleanup;
+ }
init_parser(1);
if (yyparse() || policydb_errors) {
fprintf(stderr,
"%s: error(s) encountered while parsing configuration\n",
progname);
- return -1;
+ goto cleanup;
}
rewind(yyin);
init_parser(2);
@@ -65,11 +73,15 @@ int read_source_policy(policydb_t * p, const char *file, const char *progname)
fprintf(stderr,
"%s: error(s) encountered while parsing configuration\n",
progname);
- return -1;
+ goto cleanup;
}
- queue_destroy(id_queue);
+ rc = 0;
+
+cleanup:
+ queue_destroy(id_queue);
fclose(yyin);
+ yylex_destroy();
- return 0;
+ return rc;
}
--
2.33.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/checkpolicy.git
git@gitee.com:src-openeuler/checkpolicy.git
src-openeuler
checkpolicy
checkpolicy
master

搜索帮助