From: Jouni Malinen Date: Tue, 7 Apr 2015 12:43:32 +0000 (+0300) Subject: Use common is_ctrl_char() helper function X-Git-Tag: hostap_2_5~836 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f5acfba06742617bd26ccc1b7586b399d00bef2;p=thirdparty%2Fhostap.git Use common is_ctrl_char() helper function This modifies couple of code segments that replaced control characters in strings with '_' to use a common helper function. Signed-off-by: Jouni Malinen --- diff --git a/src/p2p/p2p_parse.c b/src/p2p/p2p_parse.c index 44b00984c..def41ff51 100644 --- a/src/p2p/p2p_parse.c +++ b/src/p2p/p2p_parse.c @@ -161,8 +161,7 @@ static int p2p_parse_attribute(u8 id, const u8 *data, u16 len, for (i = 0; i < nlen; i++) { if (msg->device_name[i] == '\0') break; - if (msg->device_name[i] > 0 && - msg->device_name[i] < 32) + if (is_ctrl_char(msg->device_name[i])) msg->device_name[i] = '_'; } wpa_printf(MSG_DEBUG, "P2P: * Device Info: addr " MACSTR @@ -743,7 +742,7 @@ static int p2p_group_info_text(const u8 *gi, size_t gi_len, char *buf, name[cli->dev_name_len] = '\0'; count = (int) cli->dev_name_len - 1; while (count >= 0) { - if (name[count] > 0 && name[count] < 32) + if (is_ctrl_char(name[count])) name[count] = '_'; count--; } diff --git a/src/utils/common.c b/src/utils/common.c index c31717c77..5cf0d571b 100644 --- a/src/utils/common.c +++ b/src/utils/common.c @@ -1088,3 +1088,9 @@ size_t utf8_escape(const char *inp, size_t in_size, return res_size; } + + +int is_ctrl_char(char c) +{ + return c > 0 && c < 32; +} diff --git a/src/utils/common.h b/src/utils/common.h index a0eda4a2c..88318f5d2 100644 --- a/src/utils/common.h +++ b/src/utils/common.h @@ -554,6 +554,7 @@ size_t utf8_escape(const char *inp, size_t in_size, char *outp, size_t out_size); size_t utf8_unescape(const char *inp, size_t in_size, char *outp, size_t out_size); +int is_ctrl_char(char c); /* diff --git a/src/wps/wps.c b/src/wps/wps.c index 2c68be8c6..498f11f05 100644 --- a/src/wps/wps.c +++ b/src/wps/wps.c @@ -618,7 +618,8 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end) if (str == NULL) return pos - buf; for (i = 0; i < attr.dev_name_len; i++) { - if (attr.dev_name[i] < 32) + if (attr.dev_name[i] == 0 || + is_ctrl_char(attr.dev_name[i])) str[i] = '_'; else str[i] = attr.dev_name[i];