Patchwork ieee802_1x: remove useless NULL terminations

login
register
mail settings
Submitter Baruch Siach
Date July 5, 2012, 2:21 p.m.
Message ID <aa3de597a176e143865e73ed02cd4850205d5993.1341476306.git.baruch@tkos.co.il>
Download mbox | patch
Permalink /patch/169606/
State Rejected
Headers show

Comments

Baruch Siach - July 5, 2012, 2:21 p.m.
snprintf() is guaranteed to terminate its destination string.

Signed-hostap: Baruch Siach <baruch@tkos.co.il>
---
 src/ap/ieee802_1x.c |    3 ---
 1 file changed, 3 deletions(-)
Jouni Malinen - Aug. 4, 2012, 9:08 a.m.
On Thu, Jul 05, 2012 at 05:21:07PM +0300, Baruch Siach wrote:
> snprintf() is guaranteed to terminate its destination string.

Some snprintf() implementations may indeed do that, but not all.. For
example, _snprintf() in Visual Studio does not (or at least did not in
some versions) do that. There is even a following note on this in
documentation: "This function does not guarantee NULL termination, so
ensure it is followed by sz[ ARRAYSIZE(sz) - 1] = 0."

Patch

diff --git a/src/ap/ieee802_1x.c b/src/ap/ieee802_1x.c
index dd0df1d..7544027 100644
--- a/src/ap/ieee802_1x.c
+++ b/src/ap/ieee802_1x.c
@@ -482,7 +482,6 @@  static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
 
 	os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
 		    MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid);
-	buf[sizeof(buf) - 1] = '\0';
 	if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
 					    RADIUS_ATTR_CALLED_STATION_ID) &&
 	    !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
@@ -493,7 +492,6 @@  static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
 
 	os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
 		    MAC2STR(sta->addr));
-	buf[sizeof(buf) - 1] = '\0';
 	if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
 				 (u8 *) buf, os_strlen(buf))) {
 		printf("Could not add Calling-Station-Id\n");
@@ -526,7 +524,6 @@  static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
 			    radius_sta_rate(hapd, sta) / 2,
 			    (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
 			    radius_mode_txt(hapd));
-		buf[sizeof(buf) - 1] = '\0';
 	}
 	if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
 					    RADIUS_ATTR_CONNECT_INFO) &&