Accepting request 540066 from home:BinLiu:branches:network:ha-clustering:Factory

- gcc: snprintf gives warning: ‘%s’ directive output may be truncated writing
       8 bytes into a region of size between 1 and 255(nsc#1066090)
    Added: 0006-Fix-compile-warnings-with-GCC-7.2.1.patch

OBS-URL: https://build.opensuse.org/request/show/540066
OBS-URL: https://build.opensuse.org/package/show/network:ha-clustering:Factory/corosync?expand=0&rev=117
This commit is contained in:
Bin Liu 2017-11-09 05:50:58 +00:00 committed by Git OBS Bridge
parent 4c8b0e71aa
commit a9ba154cbc
3 changed files with 181 additions and 0 deletions

View File

@ -0,0 +1,172 @@
1. sam: Fix snprintf compiler warnings
2. cpg_test_agent: Fix snprintf compiler warnings
3. quorumtool: Use full buffer size in snprintf
4. readdir_r is deprecated in glibc 2.24 in favor of readdir
---
cts/agents/cpg_test_agent.c | 8 ++++----
exec/coroparse.c | 18 +++---------------
lib/sam.c | 36 ++++++++++++++++++++++++++++--------
tools/corosync-quorumtool.c | 2 +-
4 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/cts/agents/cpg_test_agent.c b/cts/agents/cpg_test_agent.c
index 0837c69c..2224141c 100644
--- a/cts/agents/cpg_test_agent.c
+++ b/cts/agents/cpg_test_agent.c
@@ -211,8 +211,8 @@ static void config_change_callback (
if (record_config_events_g > 0) {
log_pt = malloc (sizeof(log_entry_t));
list_init (&log_pt->list);
- snprintf (log_pt->log, LOG_STR_SIZE, "%s,%u,%u,left",
- groupName->value, left_list[i].nodeid,left_list[i].pid);
+ assert(snprintf (log_pt->log, LOG_STR_SIZE, "%s,%u,%u,left",
+ groupName->value, left_list[i].nodeid,left_list[i].pid) < LOG_STR_SIZE);
list_add_tail(&log_pt->list, &config_chg_log_head);
qb_log (LOG_INFO, "cpg event %s", log_pt->log);
}
@@ -221,8 +221,8 @@ static void config_change_callback (
if (record_config_events_g > 0) {
log_pt = malloc (sizeof(log_entry_t));
list_init (&log_pt->list);
- snprintf (log_pt->log, LOG_STR_SIZE, "%s,%u,%u,join",
- groupName->value, joined_list[i].nodeid,joined_list[i].pid);
+ assert(snprintf (log_pt->log, LOG_STR_SIZE, "%s,%u,%u,join",
+ groupName->value, joined_list[i].nodeid,joined_list[i].pid) < LOG_STR_SIZE);
list_add_tail (&log_pt->list, &config_chg_log_head);
qb_log (LOG_INFO, "cpg event %s", log_pt->log);
}
diff --git a/exec/coroparse.c b/exec/coroparse.c
index 2777a632..96bb83a5 100644
--- a/exec/coroparse.c
+++ b/exec/coroparse.c
@@ -1241,11 +1241,8 @@ static int read_uidgid_files_into_icmap(
const char *dirname;
DIR *dp;
struct dirent *dirent;
- struct dirent *entry;
char filename[PATH_MAX + FILENAME_MAX + 1];
int res = 0;
- size_t len;
- int return_code;
struct stat stat_buf;
enum main_cp_cb_data_state state = MAIN_CP_CB_DATA_STATE_NORMAL;
char key_name[ICMAP_KEYNAME_MAXLEN];
@@ -1256,17 +1253,9 @@ static int read_uidgid_files_into_icmap(
if (dp == NULL)
return 0;
- len = offsetof(struct dirent, d_name) + FILENAME_MAX + 1;
-
- entry = malloc(len);
- if (entry == NULL) {
- res = 0;
- goto error_exit;
- }
-
- for (return_code = readdir_r(dp, entry, &dirent);
- dirent != NULL && return_code == 0;
- return_code = readdir_r(dp, entry, &dirent)) {
+ for (dirent = readdir(dp);
+ dirent != NULL;
+ dirent = readdir(dp)) {
snprintf(filename, sizeof (filename), "%s/%s", dirname, dirent->d_name);
res = stat (filename, &stat_buf);
@@ -1288,7 +1277,6 @@ static int read_uidgid_files_into_icmap(
}
error_exit:
- free (entry);
closedir(dp);
return res;
diff --git a/lib/sam.c b/lib/sam.c
index 33aa3944..527b99cb 100644
--- a/lib/sam.c
+++ b/lib/sam.c
@@ -145,6 +145,7 @@ static cs_error_t sam_cmap_update_key (enum sam_cmap_key_t key, const char *valu
cs_error_t err;
const char *svalue;
uint64_t hc_period, last_hc;
+
const char *ssvalue[] = { [SAM_RECOVERY_POLICY_QUIT] = "quit", [SAM_RECOVERY_POLICY_RESTART] = "restart" };
char key_name[CMAP_KEYNAME_MAXLEN];
@@ -152,8 +153,13 @@ static cs_error_t sam_cmap_update_key (enum sam_cmap_key_t key, const char *valu
case SAM_CMAP_KEY_RECOVERY:
svalue = ssvalue[SAM_RP_MASK (sam_internal_data.recovery_policy)];
- snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
- "recovery");
+ if (snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
+ "recovery") >= CMAP_KEYNAME_MAXLEN) {
+
+ err = CS_ERR_NAME_TOO_LONG;
+ goto exit_error;
+ }
+
if ((err = cmap_set_string(sam_internal_data.cmap_handle, key_name, svalue)) != CS_OK) {
goto exit_error;
}
@@ -161,8 +167,13 @@ static cs_error_t sam_cmap_update_key (enum sam_cmap_key_t key, const char *valu
case SAM_CMAP_KEY_HC_PERIOD:
hc_period = sam_internal_data.time_interval;
- snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
- "poll_period");
+ if (snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
+ "poll_period") >= CMAP_KEYNAME_MAXLEN) {
+
+ err = CS_ERR_NAME_TOO_LONG;
+ goto exit_error;
+ }
+
if ((err = cmap_set_uint64(sam_internal_data.cmap_handle, key_name, hc_period)) != CS_OK) {
goto exit_error;
}
@@ -170,16 +181,25 @@ static cs_error_t sam_cmap_update_key (enum sam_cmap_key_t key, const char *valu
case SAM_CMAP_KEY_LAST_HC:
last_hc = cs_timestamp_get();
- snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
- "last_updated");
+ if (snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
+ "last_updated") >= CMAP_KEYNAME_MAXLEN) {
+
+ err = CS_ERR_NAME_TOO_LONG;
+ goto exit_error;
+ }
if ((err = cmap_set_uint64(sam_internal_data.cmap_handle, key_name, last_hc)) != CS_OK) {
goto exit_error;
}
break;
case SAM_CMAP_KEY_STATE:
svalue = value;
- snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
- "state");
+ if (snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
+ "state") >= CMAP_KEYNAME_MAXLEN) {
+
+ err = CS_ERR_NAME_TOO_LONG;
+ goto exit_error;
+ }
+
if ((err = cmap_set_string(sam_internal_data.cmap_handle, key_name, svalue)) != CS_OK) {
goto exit_error;
}
diff --git a/tools/corosync-quorumtool.c b/tools/corosync-quorumtool.c
index 52c141ce..19696659 100644
--- a/tools/corosync-quorumtool.c
+++ b/tools/corosync-quorumtool.c
@@ -519,7 +519,7 @@ static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name
if (info[i].flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED) {
char buf[10];
- snprintf(buf, sizeof(buf) - 1,
+ snprintf(buf, sizeof(buf),
"%s,%s,%s",
info[i].flags & VOTEQUORUM_INFO_QDEVICE_ALIVE?"A":"NA",
info[i].flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE?"V":"NV",
--
2.13.6

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Nov 9 03:06:36 UTC 2017 - bliu@suse.com
- gcc: snprintf gives warning: %s directive output may be truncated writing
8 bytes into a region of size between 1 and 255(nsc#1066090)
Added: 0006-Fix-compile-warnings-with-GCC-7.2.1.patch
-------------------------------------------------------------------
Mon Nov 6 09:14:55 UTC 2017 - bliu@suse.com

View File

@ -62,6 +62,7 @@ Patch9: 0002-fix-ifdown-udp.patch
Patch10: 0003-fix-tmpfiles-create.patch
Patch11: 0004-mark-corosync-as-a-static-service.patch
Patch12: 0005-do-not-convert-empty-uid-gid-to-0.patch
Patch13: 0006-Fix-compile-warnings-with-GCC-7.2.1.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
# openais is indeed gone and should be uninstalled. Yes, we do not
@ -139,6 +140,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-build
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%build
%if %{with runautogen}