diff --git a/0001-fix-env-Fix-the-pointer-position-update-error-after--f0d6941b.patch b/0001-fix-env-Fix-the-pointer-position-update-error-after--f0d6941b.patch new file mode 100644 index 0000000..1791a58 --- /dev/null +++ b/0001-fix-env-Fix-the-pointer-position-update-error-after--f0d6941b.patch @@ -0,0 +1,31 @@ +From f0d6941ba9ea9044237a4eb350a92bc5fa72e07a Mon Sep 17 00:00:00 2001 +From: tangjie02 +Date: Fri, 14 May 2021 18:58:25 +0800 +Subject: [PATCH 1/2] fix(env): Fix the pointer position update error after + enviroment variable is replaced. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 修复环境变量替换后指针计算错误问题 + +Signed-off-by: tangjie02 +--- + src/zc_util.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/zc_util.c b/src/zc_util.c +index 93745ae..b5ee1c2 100644 +--- a/src/zc_util.c ++++ b/src/zc_util.c +@@ -144,6 +144,7 @@ int zc_str_replace_env(char *str, size_t str_size) + + memmove(p + env_value_len, q, strlen(q) + 1); + memcpy(p, env_value, env_value_len); ++ q = p + env_value_len; + + } while (1); + +-- +2.27.0 + diff --git a/0002-feature-mkdir-If-the-output-directory-does-not-exist-5c55d7d4.patch b/0002-feature-mkdir-If-the-output-directory-does-not-exist-5c55d7d4.patch new file mode 100644 index 0000000..cdea78f --- /dev/null +++ b/0002-feature-mkdir-If-the-output-directory-does-not-exist-5c55d7d4.patch @@ -0,0 +1,261 @@ +From 5c55d7d4b9de45d3aeb931b3b34d2232a975ae8c Mon Sep 17 00:00:00 2001 +From: tangjie02 +Date: Sat, 12 Dec 2020 16:32:49 +0800 +Subject: [PATCH 2/2] feature(mkdir): If the output directory does not exist, + it will be created automatically. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 日志输出目录不存在则自动创建 + +Signed-off-by: tangjie02 +--- + src/conf.c | 7 +++++++ + src/conf.h | 1 + + src/rule.c | 24 ++++++++++++++++++++++++ + src/rule.h | 2 ++ + src/zc_util.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ + src/zc_util.h | 1 + + 6 files changed, 83 insertions(+) + +diff --git a/src/conf.c b/src/conf.c +index c592153..a947178 100644 +--- a/src/conf.c ++++ b/src/conf.c +@@ -30,6 +30,7 @@ + #define ZLOG_CONF_DEFAULT_BUF_SIZE_MIN 1024 + #define ZLOG_CONF_DEFAULT_BUF_SIZE_MAX (2 * 1024 * 1024) + #define ZLOG_CONF_DEFAULT_FILE_PERMS 0600 ++#define ZLOG_CONF_DEFAULT_DIRECTORY_PERMS 0755 + #define ZLOG_CONF_DEFAULT_RELOAD_CONF_PERIOD 0 + #define ZLOG_CONF_DEFAULT_FSYNC_PERIOD 0 + #define ZLOG_CONF_BACKUP_ROTATE_LOCK_FILE "/tmp/zlog.lock" +@@ -54,6 +55,7 @@ void zlog_conf_profile(zlog_conf_t * a_conf, int flag) + zlog_format_profile(a_conf->default_format, flag); + } + zc_profile(flag, "---file perms[0%o]---", a_conf->file_perms); ++ zc_profile(flag, "---directory perms[0%o]---", a_conf->directory_perms); + zc_profile(flag, "---reload conf period[%ld]---", a_conf->reload_conf_period); + zc_profile(flag, "---fsync period[%ld]---", a_conf->fsync_period); + +@@ -150,6 +152,7 @@ zlog_conf_t *zlog_conf_new(const char *config) + } + strcpy(a_conf->default_format_line, ZLOG_CONF_DEFAULT_FORMAT); + a_conf->file_perms = ZLOG_CONF_DEFAULT_FILE_PERMS; ++ a_conf->directory_perms = ZLOG_CONF_DEFAULT_DIRECTORY_PERMS; + a_conf->reload_conf_period = ZLOG_CONF_DEFAULT_RELOAD_CONF_PERIOD; + a_conf->fsync_period = ZLOG_CONF_DEFAULT_FSYNC_PERIOD; + /* set default configuration end */ +@@ -218,6 +221,7 @@ static int zlog_conf_build_without_file(zlog_conf_t * a_conf) + a_conf->default_format, + a_conf->formats, + a_conf->file_perms, ++ a_conf->directory_perms, + a_conf->fsync_period, + &(a_conf->time_cache_count)); + if (!default_rule) { +@@ -485,6 +489,8 @@ static int zlog_conf_parse_line(zlog_conf_t * a_conf, char *line, int *section) + a_conf->buf_size_max = zc_parse_byte_size(value); + } else if (STRCMP(word_1, ==, "file") && STRCMP(word_2, ==, "perms")) { + sscanf(value, "%o", &(a_conf->file_perms)); ++ } else if (STRCMP(word_1, ==, "directory") && STRCMP(word_2, ==, "perms")) { ++ sscanf(value, "%o", &(a_conf->directory_perms)); + } else if (STRCMP(word_1, ==, "rotate") && + STRCMP(word_2, ==, "lock") && STRCMP(word_3, ==, "file")) { + /* may overwrite the inner default value, or last value */ +@@ -531,6 +537,7 @@ static int zlog_conf_parse_line(zlog_conf_t * a_conf, char *line, int *section) + a_conf->default_format, + a_conf->formats, + a_conf->file_perms, ++ a_conf->directory_perms, + a_conf->fsync_period, + &(a_conf->time_cache_count)); + +diff --git a/src/conf.h b/src/conf.h +index 159325e..247bd0b 100644 +--- a/src/conf.h ++++ b/src/conf.h +@@ -29,6 +29,7 @@ typedef struct zlog_conf_s { + zlog_format_t *default_format; + + unsigned int file_perms; ++ unsigned int directory_perms; + size_t fsync_period; + size_t reload_conf_period; + +diff --git a/src/rule.c b/src/rule.c +index ae3d74f..473d21f 100644 +--- a/src/rule.c ++++ b/src/rule.c +@@ -100,6 +100,11 @@ static int zlog_rule_output_static_file_single(zlog_rule_t * a_rule, zlog_thread + + if (do_file_reload) { + close(a_rule->static_fd); ++ ++ if (zc_mkdir_with_parents(a_rule->file_path, a_rule->directory_perms) < 0) { ++ return -1; ++ } ++ + a_rule->static_fd = open(a_rule->file_path, + O_WRONLY | O_APPEND | O_CREAT | a_rule->file_open_flags, + a_rule->file_perms); +@@ -168,6 +173,10 @@ static int zlog_rule_output_static_file_rotate(zlog_rule_t * a_rule, zlog_thread + return -1; + } + ++ if (zc_mkdir_with_parents(a_rule->file_path, a_rule->directory_perms) < 0) { ++ return -1; ++ } ++ + fd = open(a_rule->file_path, + a_rule->file_open_flags | O_WRONLY | O_APPEND | O_CREAT, a_rule->file_perms); + if (fd < 0) { +@@ -249,6 +258,10 @@ static int zlog_rule_output_dynamic_file_single(zlog_rule_t * a_rule, zlog_threa + return -1; + } + ++ if (zc_mkdir_with_parents(a_rule->file_path, a_rule->directory_perms) < 0) { ++ return -1; ++ } ++ + fd = open(zlog_buf_str(a_thread->path_buf), + a_rule->file_open_flags | O_WRONLY | O_APPEND | O_CREAT, a_rule->file_perms); + if (fd < 0) { +@@ -290,6 +303,11 @@ static int zlog_rule_output_dynamic_file_rotate(zlog_rule_t * a_rule, zlog_threa + } + + path = zlog_buf_str(a_thread->path_buf); ++ ++ if (zc_mkdir_with_parents(path, a_rule->directory_perms) < 0) { ++ return -1; ++ } ++ + fd = open(path, a_rule->file_open_flags | O_WRONLY | O_APPEND | O_CREAT, a_rule->file_perms); + if (fd < 0) { + zc_error("open file[%s] fail, errno[%d]", zlog_buf_str(a_thread->path_buf), errno); +@@ -566,6 +584,7 @@ zlog_rule_t *zlog_rule_new(char *line, + zlog_format_t * default_format, + zc_arraylist_t * formats, + unsigned int file_perms, ++ unsigned int directory_perms, + size_t fsync_period, + int * time_cache_count) + { +@@ -600,6 +619,7 @@ zlog_rule_t *zlog_rule_new(char *line, + } + + a_rule->file_perms = file_perms; ++ a_rule->directory_perms = directory_perms; + a_rule->fsync_period = fsync_period; + + /* line [f.INFO "%H/log/aa.log", 20MB * 12; MyTemplate] +@@ -810,6 +830,10 @@ zlog_rule_t *zlog_rule_new(char *line, + a_rule->output = zlog_rule_output_static_file_rotate; + } + ++ if (zc_mkdir_with_parents(a_rule->file_path, a_rule->directory_perms) < 0) { ++ goto err; ++ } ++ + a_rule->static_fd = open(a_rule->file_path, + O_WRONLY | O_APPEND | O_CREAT | a_rule->file_open_flags, + a_rule->file_perms); +diff --git a/src/rule.h b/src/rule.h +index e562185..39417e2 100644 +--- a/src/rule.h ++++ b/src/rule.h +@@ -40,6 +40,7 @@ struct zlog_rule_s { + unsigned char level_bitmap[32]; /* for category determine whether ouput or not */ + + unsigned int file_perms; ++ unsigned int directory_perms; + int file_open_flags; + + char file_path[MAXLEN_PATH + 1]; +@@ -75,6 +76,7 @@ zlog_rule_t *zlog_rule_new(char * line, + zlog_format_t * default_format, + zc_arraylist_t * formats, + unsigned int file_perms, ++ unsigned int directory_perms, + size_t fsync_period, + int * time_cache_count); + +diff --git a/src/zc_util.c b/src/zc_util.c +index 07deb22..93745ae 100644 +--- a/src/zc_util.c ++++ b/src/zc_util.c +@@ -12,6 +12,10 @@ + #include + #include + #include ++#include ++#include ++#include ++ + + #include "zc_defs.h" + +@@ -145,3 +149,47 @@ int zc_str_replace_env(char *str, size_t str_size) + + return 0; + } ++ ++int zc_mkdir_with_parents(const char *path, unsigned int perms) ++{ ++ char str[MAXLEN_PATH]; ++ int str_len; ++ int i; ++ ++ str_len = snprintf(str, MAXLEN_PATH, "%s", path); ++ if (str_len <= 0 || str_len >= MAXLEN_PATH) ++ { ++ zc_error("snprintf fail, errno[%d], str_len[%d]", ++ errno, str_len); ++ return -1; ++ } ++ ++ if (str[str_len - 1] == '/') ++ { ++ --str_len; ++ } ++ ++ while (str_len > 0 && str[str_len - 1] != '/') ++ { ++ --str_len; ++ } ++ str[str_len] = 0; ++ ++ for (i = 1; i < str_len; i++) ++ { ++ if (str[i] == '/') ++ { ++ str[i] = 0; ++ if (access(str, F_OK) != 0) ++ { ++ if (mkdir(str, perms) == -1) ++ { ++ zc_error("mkdir error, errno[%d] str[%s]", errno, str); ++ return -1; ++ } ++ } ++ str[i] = '/'; ++ } ++ } ++ return 0; ++} +diff --git a/src/zc_util.h b/src/zc_util.h +index 3f032cd..dbdeaf5 100644 +--- a/src/zc_util.h ++++ b/src/zc_util.h +@@ -10,6 +10,7 @@ + + size_t zc_parse_byte_size(char *astring); + int zc_str_replace_env(char *str, size_t str_size); ++int zc_mkdir_with_parents(const char *path, unsigned int perms); + + #define zc_max(a,b) ((a) > (b) ? (a) : (b)) + #define zc_min(a,b) ((a) < (b) ? (a) : (b)) +-- +2.27.0 + diff --git a/1012-feature-environment-Ignore-the-rule-when-the-environ-40ea87cd.patch b/1012-feature-environment-Ignore-the-rule-when-the-environ-40ea87cd.patch new file mode 100644 index 0000000..6b9fcbe --- /dev/null +++ b/1012-feature-environment-Ignore-the-rule-when-the-environ-40ea87cd.patch @@ -0,0 +1,32 @@ +From 40ea87cd0b2073a622b3186900faaace7e6ca57b Mon Sep 17 00:00:00 2001 +From: tangjie02 +Date: Fri, 9 Jul 2021 10:25:48 +0800 +Subject: [PATCH 1012/1013] feature(environment): Ignore the rule when the + environment in %E(env) isn't found. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 当通过%E(env)语法表示的环境变量未找到时忽略该条规则 + +Signed-off-by: tangjie02 +--- + src/zc_util.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/zc_util.c b/src/zc_util.c +index b5ee1c2..a77c763 100644 +--- a/src/zc_util.c ++++ b/src/zc_util.c +@@ -130,7 +130,7 @@ int zc_str_replace_env(char *str, size_t str_size) + } + + env_value_len = snprintf(env_value, sizeof(env_value), fmt, getenv(env_key)); +- if (env_value_len < 0 || env_value_len >= sizeof(env_value)) { ++ if (getenv(env_key) == NULL || env_value_len < 0 || env_value_len >= sizeof(env_value)) { + zc_error("snprintf fail, errno[%d], evn_value_len[%d]", + errno, env_value_len); + return -1; +-- +2.27.0 + diff --git a/zlog.spec b/zlog.spec index f75bb8e..e54423d 100644 --- a/zlog.spec +++ b/zlog.spec @@ -1,12 +1,17 @@ Name: zlog Version: 1.2.15 -Release: 4 +Release: 5 Summary: A reliable pure C logging library License: LGPLv2.1 URL: http://hardysimpson.github.io/zlog/ Source0: %{name}-%{version}.tar.gz + Patch1000: 0001-Fix-stack-buffer-overflow-at-zlog_conf_build_with_fi.patch +Patch1001: 0002-feature-mkdir-If-the-output-directory-does-not-exist-5c55d7d4.patch +Patch1002: 0001-fix-env-Fix-the-pointer-position-update-error-after--f0d6941b.patch +Patch1003: 1012-feature-environment-Ignore-the-rule-when-the-environ-40ea87cd.patch + BuildRequires: gcc-c++ #Requires: @@ -47,6 +52,11 @@ ln -sf libzlog.so.1.2 '%{buildroot}/%{_libdir}/libzlog.so' %changelog +* Mon Sep 26 2022 tangjie02 - 1.2.15-5 +- if the output directory does not exist, it will be created automatically. +- fix the pointer position update error after enviroment variable is replaced. +- ignore the rule when the environment in %E(env) isn't found. + * Mon Apr 25 2022 yefeng - 1.2.15-4 - fix the CVE-2021-43521