Skip to content

Commit

Permalink
issue: 1137302 Solve gcc7.x [format-overflow]
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Ivanov <igor.ivanov.va@gmail.com>
  • Loading branch information
igor-ivanov authored and Liran Oz committed Sep 18, 2017
1 parent faf3f7b commit b5cb1e3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/stats/stats_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ void vma_shmem_stats_open(vlog_levels_t** p_p_vma_log_level, uint8_t** p_p_vma_l

g_sh_mem_info.filename_sh_stats[0] = '\0';
g_sh_mem_info.p_sh_stats = MAP_FAILED;
sprintf(g_sh_mem_info.filename_sh_stats, "%s/vmastat.%d", safe_mce_sys().stats_shmem_dirname, getpid());
ret = snprintf(g_sh_mem_info.filename_sh_stats, sizeof(g_sh_mem_info.filename_sh_stats), "%s/vmastat.%d", safe_mce_sys().stats_shmem_dirname, getpid());
if (!((0 < ret) && (ret < (int)sizeof(g_sh_mem_info.filename_sh_stats)))) {
vlog_printf(VLOG_ERROR, "%s: Could not create file under %s %m\n", __func__, safe_mce_sys().stats_shmem_dirname, errno);
goto no_shmem;
}
saved_mode = umask(0);
g_sh_mem_info.fd_sh_stats = open(g_sh_mem_info.filename_sh_stats, O_CREAT|O_RDWR, S_IRWXU | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
umask(saved_mode);
Expand Down
2 changes: 1 addition & 1 deletion src/vma/config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void __vma_set_ipv4_addr(short a0, short a1, short a2, short a3)

p_ipv4 = &(__vma_address_port_rule->ipv4);

sprintf(buf,"%d.%d.%d.%d", a0, a1, a2, a3);
snprintf(buf, sizeof(buf), "%hd.%hd.%hd.%hd", a0, a1, a2, a3);
if (1 != inet_pton(AF_INET, (const char*)buf, p_ipv4)) {
parse_err = 1;
yyerror("provided address is not legal");
Expand Down
7 changes: 4 additions & 3 deletions src/vma/dev/net_device_table_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ bool net_device_table_mgr::verify_eth_qp_creation(const char* ifname, uint8_t po
priv_safe_read_file(resource_path, sys_res, 1024);
for (int j=0; j<num_devices; j++) {
char ib_res[1024] = {0};
char ib_path[256] = {0};
sprintf(ib_path, "%s/device/resource", pp_ibv_context_list[j]->device->ibdev_path);
priv_safe_read_file(ib_path, ib_res, 1024);
const char ib_path_format[] = "%s/device/resource";
char ib_path[IBV_SYSFS_PATH_MAX + sizeof(ib_path_format)] = {0};
snprintf(ib_path, sizeof(ib_path), ib_path_format, pp_ibv_context_list[j]->device->ibdev_path);
priv_safe_read_file(ib_path, ib_res, sizeof(ib_res));
if (strcmp(sys_res, ib_res) == 0) {
//create qp resources
ib_ctx_handler* p_ib_ctx = g_p_ib_ctx_handler_collection->get_ib_ctx(pp_ibv_context_list[j]);
Expand Down
7 changes: 4 additions & 3 deletions src/vma/dev/net_device_val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ void net_device_val::configure(struct ifaddrs* ifa, struct rdma_cm_id* cma_id)
// find the ibv context and port num
for (int j=0; j<num_devices; j++) {
char ib_res[1024] = {0};
char ib_path[256] = {0};
sprintf(ib_path, "%s/device/resource", pp_ibv_context_list[j]->device->ibdev_path);
if (priv_read_file(ib_path, ib_res, 1024) <= 0) {
const char ib_path_format[] = "%s/device/resource";
char ib_path[IBV_SYSFS_PATH_MAX + sizeof(ib_path_format)] = {0};
snprintf(ib_path, sizeof(ib_path), ib_path_format, pp_ibv_context_list[j]->device->ibdev_path);
if (priv_read_file(ib_path, ib_res, sizeof(ib_res)) <= 0) {
continue;
}
if (strcmp(sys_res, ib_res) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/vma/proto/flow_tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool flow_tuple::is_3_tuple()
void flow_tuple::set_str()
{
/* cppcheck-suppress wrongPrintfScanfArgNum */
snprintf(m_str, STR_MAX_LENGTH, "dst:%d.%d.%d.%d:%d, src:%d.%d.%d.%d:%d, protocol:%s",
snprintf(m_str, sizeof(m_str), "dst:%hhu.%hhu.%hhu.%hhu:%hu, src:%hhu.%hhu.%hhu.%hhu:%hu, proto:%s",
NIPQUAD(m_dst_ip), ntohs(m_dst_port),
NIPQUAD(m_src_ip), ntohs(m_src_port),
__vma_get_protocol_str(m_protocol));
Expand All @@ -174,7 +174,7 @@ void flow_tuple::set_str()
void flow_tuple_with_local_if::set_str()
{
/* cppcheck-suppress wrongPrintfScanfArgNum */
snprintf(m_str, STR_MAX_LENGTH, "dst:%d.%d.%d.%d:%d, src:%d.%d.%d.%d:%d, protocol:%s, local if:%d.%d.%d.%d",
snprintf(m_str, sizeof(m_str), "dst:%hhu.%hhu.%hhu.%hhu:%hu, src:%hhu.%hhu.%hhu.%hhu:%hu, proto:%s, if:%hhu.%hhu.%hhu.%hhu",
NIPQUAD(m_dst_ip), ntohs(m_dst_port),
NIPQUAD(m_src_ip), ntohs(m_src_port),
__vma_get_protocol_str(m_protocol), NIPQUAD(m_local_if));
Expand Down
4 changes: 2 additions & 2 deletions src/vma/proto/flow_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class flow_tuple
{
uint8_t csum = 0;
uint8_t* pval = (uint8_t*)this;
for (size_t i = 0; i < (sizeof(flow_tuple)-STR_MAX_LENGTH); ++i, ++pval) { csum ^= *pval; }
for (size_t i = 0; i < (sizeof(flow_tuple) - sizeof(m_str)); ++i, ++pval) { csum ^= *pval; }
return csum;
}
#if _BullseyeCoverage
Expand Down Expand Up @@ -156,7 +156,7 @@ class flow_tuple_with_local_if : public flow_tuple
{
uint8_t csum = 0;
uint8_t* pval = (uint8_t*)this;
for (size_t i = 0; i < (sizeof(flow_tuple_with_local_if)-STR_MAX_LENGTH); ++i, ++pval) { csum ^= *pval; }
for (size_t i = 0; i < (sizeof(flow_tuple_with_local_if) - sizeof(m_str)); ++i, ++pval) { csum ^= *pval; }
return csum;
}

Expand Down
8 changes: 4 additions & 4 deletions src/vma/util/sys_vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ struct mce_sys_var {

vlog_levels_t log_level;
uint32_t log_details;
char log_filename[FILENAME_MAX];
char stats_filename[FILENAME_MAX];
char stats_shmem_dirname[FILENAME_MAX];
char conf_filename[FILENAME_MAX];
char log_filename[FILE_NAME_MAX_SIZE];
char stats_filename[FILE_NAME_MAX_SIZE];
char stats_shmem_dirname[FILE_NAME_MAX_SIZE];
char conf_filename[FILE_NAME_MAX_SIZE];
bool log_colors;
bool handle_sigintr;
bool handle_segfault;
Expand Down

0 comments on commit b5cb1e3

Please sign in to comment.