diff --git a/mtce-common/src/common/httpUtil.cpp b/mtce-common/src/common/httpUtil.cpp index 469d945a..534125c1 100644 --- a/mtce-common/src/common/httpUtil.cpp +++ b/mtce-common/src/common/httpUtil.cpp @@ -761,11 +761,6 @@ int httpUtil_api_request ( libEvent & event ) { ; } - - else if ( TEST_WITH_NO_TOKEN ) - { - ; - } else { slog ("%s Unsupported Request (%d)\n", event.hostname.c_str(), event.request); diff --git a/mtce-common/src/common/httpUtil.h b/mtce-common/src/common/httpUtil.h index f39c460d..f108e2b3 100644 --- a/mtce-common/src/common/httpUtil.h +++ b/mtce-common/src/common/httpUtil.h @@ -158,9 +158,6 @@ typedef enum { KEYSTONE_GET_SERVICE_LIST, KEYSTONE_GET_ENDPOINT_LIST, - TEST_WITH_NO_TOKEN, - TEST_WITH_TOKEN, - SERVICE_LAST } libEvent_enum ; diff --git a/mtce-common/src/common/msgClass.cpp b/mtce-common/src/common/msgClass.cpp index 6e876e53..afc25135 100644 --- a/mtce-common/src/common/msgClass.cpp +++ b/mtce-common/src/common/msgClass.cpp @@ -309,10 +309,13 @@ int msgClassAddr::getAddressFromInterface(const char* interface, char* address, // if it is infra then we need to determine the interface // host name. For management interface, the system hostname // is the intf hostname - char iface_hostname[MAX_HOST_NAME_SIZE+1] = {0}; - snprintf(iface_hostname, MAX_HOST_NAME_SIZE, + const char* infra_suffix = "-infra"; + size_t infra_suffix_len = sizeof(infra_suffix); + char iface_hostname[MAX_HOST_NAME_SIZE+infra_suffix_len]; + memset(iface_hostname, 0, sizeof(iface_hostname)); + snprintf(iface_hostname, sizeof(iface_hostname), "%s%s", hostname, - (((interface_type == INFRA_IFACE)) ? "-infra" : "")); + (((interface_type == INFRA_IFACE)) ? infra_suffix : "")); struct addrinfo *res = NULL; int ret = getaddrinfo(iface_hostname, NULL, NULL, &res); diff --git a/mtce-common/src/common/nodeUtil.cpp b/mtce-common/src/common/nodeUtil.cpp index a0a89cbb..fa449a54 100755 --- a/mtce-common/src/common/nodeUtil.cpp +++ b/mtce-common/src/common/nodeUtil.cpp @@ -630,7 +630,7 @@ int get_iface_macaddr ( const char * iface_ptr , string & macaddr ) char str [COL_CHARS_IN_MAC_ADDR+1] ; /* and terminator */ memset ( &str[0], 0 , COL_CHARS_IN_MAC_ADDR); - snprintf ( &str[0], COL_CHARS_IN_MAC_ADDR+1, + snprintf ( &str[0], sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x", (unsigned char)(s.ifr_hwaddr.sa_data[0]), (unsigned char)(s.ifr_hwaddr.sa_data[1]), @@ -665,7 +665,7 @@ string get_iface_mac ( const char * iface_ptr ) char str [COL_CHARS_IN_MAC_ADDR+1] ; /* and terminator */ memset ( &str[0], 0 , COL_CHARS_IN_MAC_ADDR); - snprintf ( &str[0], COL_CHARS_IN_MAC_ADDR, + snprintf ( &str[0], sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x", (unsigned char)(s.ifr_hwaddr.sa_data[0]), (unsigned char)(s.ifr_hwaddr.sa_data[1]), diff --git a/mtce-common/src/daemon/daemon_files.cpp b/mtce-common/src/daemon/daemon_files.cpp index 64af6e32..0d6dbb3c 100755 --- a/mtce-common/src/daemon/daemon_files.cpp +++ b/mtce-common/src/daemon/daemon_files.cpp @@ -777,7 +777,16 @@ string get_shadow_signature ( char * shadowfile , const char * username, continue; } - char shadowEntry[BUFFER] = {0}; + /* at max, both password[] and aging[] include BUFFER chars (BUFFER-1 + * meaningful chars and one "\0" as tail). when they are combined with + * ":" and put into shadowEntry by snprintf (..., "%s:%s", ...), + * shadowEntry has 2 chars (":" + "\0") at least and BUFFER*2 chars at most: + * BUFFER-1 chars copied from password + * ":" + * BUFFER-1 chars copied from aging, and + * one tail "\0" + */ + char shadowEntry[BUFFER*2] = {0}; snprintf (shadowEntry, sizeof(shadowEntry), "%s:%s", password, aging); @@ -931,8 +940,10 @@ void daemon_rename_file ( const char * path, const char * old_filename, const ch void daemon_remove_pidfile ( void ) { - char str [64] ; - sprintf (str, "rm -f %s", pid_filename ); + const char* cmd_str = "rm -f "; + size_t cmd_len = sizeof(cmd_str); + char str [MAX_FILENAME_LEN+cmd_len] ; + snprintf (str, sizeof(str), "rm -f %s", pid_filename); int rc = system (str); if ( rc ) { diff --git a/mtce-common/src/daemon/daemon_ini.cpp b/mtce-common/src/daemon/daemon_ini.cpp index e031b5d5..a810ab8e 100755 --- a/mtce-common/src/daemon/daemon_ini.cpp +++ b/mtce-common/src/daemon/daemon_ini.cpp @@ -56,7 +56,7 @@ static char* find_char_or_comment(const char* s, char c) /* Version of strncpy that ensures dest (size bytes) is null-terminated. */ static char* strncpy0(char* dest, const char* src, size_t size) { - strncpy(dest, src, size); + strncpy(dest, src, size-1); dest[size - 1] = '\0'; return dest; }