diff options
author | Dexuan Cui <decui@microsoft.com> | 2018-10-18 01:09:32 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-11-11 15:58:27 -0500 |
commit | 4fcba7802c3e15a6e56e255871d6c72f829b9dd8 (patch) | |
tree | d12b055179213bb74dc40efaadc757943141f49b | |
parent | 16d1342bc41ad417812f8a800a1799b5d1c026dc (diff) |
Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1
The patch fixes:
hv_kvp_daemon.c: In function 'kvp_set_ip_info':
hv_kvp_daemon.c:1305:2: note: 'snprintf' output between 41 and 4136 bytes
into a destination of size 4096
The "(unsigned int)str_len" is to avoid:
hv_kvp_daemon.c:1309:30: warning: comparison of integer expressions of
different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Cc: K. Y. Srinivasan <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | tools/hv/hv_kvp_daemon.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c index bbb2a8ef367c..d7e06fe0270e 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c | |||
@@ -1178,6 +1178,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) | |||
1178 | FILE *file; | 1178 | FILE *file; |
1179 | char cmd[PATH_MAX]; | 1179 | char cmd[PATH_MAX]; |
1180 | char *mac_addr; | 1180 | char *mac_addr; |
1181 | int str_len; | ||
1181 | 1182 | ||
1182 | /* | 1183 | /* |
1183 | * Set the configuration for the specified interface with | 1184 | * Set the configuration for the specified interface with |
@@ -1301,8 +1302,18 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) | |||
1301 | * invoke the external script to do its magic. | 1302 | * invoke the external script to do its magic. |
1302 | */ | 1303 | */ |
1303 | 1304 | ||
1304 | snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s", | 1305 | str_len = snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s", |
1305 | "hv_set_ifconfig", if_file); | 1306 | "hv_set_ifconfig", if_file); |
1307 | /* | ||
1308 | * This is a little overcautious, but it's necessary to suppress some | ||
1309 | * false warnings from gcc 8.0.1. | ||
1310 | */ | ||
1311 | if (str_len <= 0 || (unsigned int)str_len >= sizeof(cmd)) { | ||
1312 | syslog(LOG_ERR, "Cmd '%s' (len=%d) may be too long", | ||
1313 | cmd, str_len); | ||
1314 | return HV_E_FAIL; | ||
1315 | } | ||
1316 | |||
1306 | if (system(cmd)) { | 1317 | if (system(cmd)) { |
1307 | syslog(LOG_ERR, "Failed to execute cmd '%s'; error: %d %s", | 1318 | syslog(LOG_ERR, "Failed to execute cmd '%s'; error: %d %s", |
1308 | cmd, errno, strerror(errno)); | 1319 | cmd, errno, strerror(errno)); |