173 lines
6.1 KiB
Diff
173 lines
6.1 KiB
Diff
|
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
|
||
|
|