Avoid preprocessor directives in macro arguments

os_snprintf() can be a preprocessor macro and according to
C99 (6.10.3 clause 11) the results of having preprocessor directives
inside the macro arguments is undefined.
This commit is contained in:
Iain Hibbert 2011-02-27 18:59:26 +02:00 committed by Jouni Malinen
parent 73304dbf65
commit 8ce58ceb25
1 changed files with 7 additions and 5 deletions

View File

@ -2479,19 +2479,21 @@ int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen)
{ {
int len = 0, ret; int len = 0, ret;
char pmkid_txt[PMKID_LEN * 2 + 1]; char pmkid_txt[PMKID_LEN * 2 + 1];
#ifdef CONFIG_RSN_PREAUTH
const int preauth = 1;
#else /* CONFIG_RSN_PREAUTH */
const int preauth = 0;
#endif /* CONFIG_RSN_PREAUTH */
if (wpa_auth == NULL) if (wpa_auth == NULL)
return len; return len;
ret = os_snprintf(buf + len, buflen - len, ret = os_snprintf(buf + len, buflen - len,
"dot11RSNAOptionImplemented=TRUE\n" "dot11RSNAOptionImplemented=TRUE\n"
#ifdef CONFIG_RSN_PREAUTH "dot11RSNAPreauthenticationImplemented=%s\n"
"dot11RSNAPreauthenticationImplemented=TRUE\n"
#else /* CONFIG_RSN_PREAUTH */
"dot11RSNAPreauthenticationImplemented=FALSE\n"
#endif /* CONFIG_RSN_PREAUTH */
"dot11RSNAEnabled=%s\n" "dot11RSNAEnabled=%s\n"
"dot11RSNAPreauthenticationEnabled=%s\n", "dot11RSNAPreauthenticationEnabled=%s\n",
wpa_bool_txt(preauth),
wpa_bool_txt(wpa_auth->conf.wpa & WPA_PROTO_RSN), wpa_bool_txt(wpa_auth->conf.wpa & WPA_PROTO_RSN),
wpa_bool_txt(wpa_auth->conf.rsn_preauth)); wpa_bool_txt(wpa_auth->conf.rsn_preauth));
if (ret < 0 || (size_t) ret >= buflen - len) if (ret < 0 || (size_t) ret >= buflen - len)