aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2009-12-19 14:34:41 (GMT)
committerJouni Malinen <j@w1.fi>2009-12-19 14:34:41 (GMT)
commit9e7245bdb414dec167363b9178a37f4745afa595 (patch)
treebcb52c9731b1af430703926c1de98124465afcca
parentd94f86d85ef1a846ff91fe3c66b368c1d535352c (diff)
downloadhostap-9e7245bdb414dec167363b9178a37f4745afa595.zip
hostap-9e7245bdb414dec167363b9178a37f4745afa595.tar.gz
hostap-9e7245bdb414dec167363b9178a37f4745afa595.tar.bz2
Change radius_msg_free() to free the buffer
Since all callers were freeing the buffer immediately anyway, move this operation into radius_msg_free() to reduce code size.
-rw-r--r--hostapd/accounting.c3
-rw-r--r--hostapd/ieee802_11_auth.c1
-rw-r--r--hostapd/ieee802_1x.c19
-rw-r--r--radius_example/radius_example.c3
-rw-r--r--src/radius/radius.c41
-rw-r--r--src/radius/radius.h8
-rw-r--r--src/radius/radius_client.c5
-rw-r--r--src/radius/radius_server.c29
-rw-r--r--wpa_supplicant/eapol_test.c13
9 files changed, 46 insertions, 76 deletions
diff --git a/hostapd/accounting.c b/hostapd/accounting.c
index 8adaf88..9297650 100644
--- a/hostapd/accounting.c
+++ b/hostapd/accounting.c
@@ -177,7 +177,6 @@ static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
fail:
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
@@ -366,7 +365,6 @@ static void accounting_sta_report(struct hostapd_data *hapd,
fail:
radius_msg_free(msg);
- os_free(msg);
}
@@ -462,7 +460,6 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
{
printf("Could not add Acct-Terminate-Cause\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
diff --git a/hostapd/ieee802_11_auth.c b/hostapd/ieee802_11_auth.c
index 981067c..9329aac 100644
--- a/hostapd/ieee802_11_auth.c
+++ b/hostapd/ieee802_11_auth.c
@@ -200,7 +200,6 @@ static int hostapd_radius_acl_query(struct hostapd_data *hapd, const u8 *addr,
fail:
radius_msg_free(msg);
- os_free(msg);
return -1;
}
#endif /* CONFIG_NO_RADIUS */
diff --git a/hostapd/ieee802_1x.c b/hostapd/ieee802_1x.c
index 813ee5e..89a11f2 100644
--- a/hostapd/ieee802_1x.c
+++ b/hostapd/ieee802_1x.c
@@ -562,7 +562,6 @@ static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
fail:
radius_msg_free(msg);
- os_free(msg);
}
#endif /* CONFIG_NO_RADIUS */
@@ -926,10 +925,7 @@ void ieee802_1x_free_station(struct sta_info *sta)
sta->eapol_sm = NULL;
#ifndef CONFIG_NO_RADIUS
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- }
+ radius_msg_free(sm->last_recv_radius);
radius_free_class(&sm->radius_class);
#endif /* CONFIG_NO_RADIUS */
@@ -1241,11 +1237,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
MAC2STR(sta->addr));
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- }
-
+ radius_msg_free(sm->last_recv_radius);
sm->last_recv_radius = msg;
session_timeout_set =
@@ -1368,11 +1360,8 @@ void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
HOSTAPD_LEVEL_DEBUG, "aborting authentication");
#ifndef CONFIG_NO_RADIUS
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- sm->last_recv_radius = NULL;
- }
+ radius_msg_free(sm->last_recv_radius);
+ sm->last_recv_radius = NULL;
#endif /* CONFIG_NO_RADIUS */
if (sm->eap_if->eapTimeout) {
diff --git a/radius_example/radius_example.c b/radius_example/radius_example.c
index 1b27efc..59982ab 100644
--- a/radius_example/radius_example.c
+++ b/radius_example/radius_example.c
@@ -74,7 +74,6 @@ static void start_example(void *eloop_ctx, void *timeout_ctx)
(u8 *) "user", 4)) {
printf("Could not add User-Name\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -84,7 +83,6 @@ static void start_example(void *eloop_ctx, void *timeout_ctx)
ctx->conf.auth_server->shared_secret_len)) {
printf("Could not add User-Password\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -92,7 +90,6 @@ static void start_example(void *eloop_ctx, void *timeout_ctx)
(u8 *) &ctx->own_ip_addr, 4)) {
printf("Could not add NAS-IP-Address\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
diff --git a/src/radius/radius.c b/src/radius/radius.c
index 7b69c9b..a00cee5 100644
--- a/src/radius/radius.c
+++ b/src/radius/radius.c
@@ -63,6 +63,15 @@ static int radius_msg_initialize(struct radius_msg *msg, size_t init_len)
}
+/**
+ * radius_msg_new - Create a new RADIUS message
+ * @code: Code for RADIUS header
+ * @identifier: Identifier for RADIUS header
+ * Returns: Context for RADIUS message or %NULL on failure
+ *
+ * The caller is responsible for freeing the returned data with
+ * radius_msg_free().
+ */
struct radius_msg * radius_msg_new(u8 code, u8 identifier)
{
struct radius_msg *msg;
@@ -82,16 +91,18 @@ struct radius_msg * radius_msg_new(u8 code, u8 identifier)
}
+/**
+ * radius_msg_free - Free a RADIUS message
+ * @msg: RADIUS message from radius_msg_new() or radius_msg_parse()
+ */
void radius_msg_free(struct radius_msg *msg)
{
- os_free(msg->buf);
- msg->buf = NULL;
- msg->hdr = NULL;
- msg->buf_size = msg->buf_used = 0;
+ if (msg == NULL)
+ return;
+ os_free(msg->buf);
os_free(msg->attr_pos);
- msg->attr_pos = NULL;
- msg->attr_size = msg->attr_used = 0;
+ os_free(msg);
}
@@ -452,7 +463,16 @@ struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
}
-struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
+/**
+ * radius_msg_parse - Parse a RADIUS message
+ * @data: RADIUS message to be parsed
+ * @len: Length of data buffer in octets
+ * Returns: Parsed RADIUS message or %NULL on failure
+ *
+ * This parses a RADIUS message and makes a copy of its data. The caller is
+ * responsible for freeing the returned data with radius_msg_free().
+ */
+struct radius_msg * radius_msg_parse(const u8 *data, size_t len)
{
struct radius_msg *msg;
struct radius_hdr *hdr;
@@ -467,13 +487,13 @@ struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
msg_len = ntohs(hdr->length);
if (msg_len < sizeof(*hdr) || msg_len > len) {
- printf("Invalid RADIUS message length\n");
+ wpa_printf(MSG_INFO, "RADIUS: Invalid message length");
return NULL;
}
if (msg_len < len) {
- printf("Ignored %lu extra bytes after RADIUS message\n",
- (unsigned long) len - msg_len);
+ wpa_printf(MSG_DEBUG, "RADIUS: Ignored %lu extra bytes after "
+ "RADIUS message", (unsigned long) len - msg_len);
}
msg = os_zalloc(sizeof(*msg));
@@ -512,7 +532,6 @@ struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
fail:
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
diff --git a/src/radius/radius.h b/src/radius/radius.h
index 9f77a5a..6050b54 100644
--- a/src/radius/radius.h
+++ b/src/radius/radius.h
@@ -230,7 +230,7 @@ struct radius_msg {
/* MAC address ASCII format for non-802.1X use */
#define RADIUS_ADDR_FORMAT "%02x%02x%02x%02x%02x%02x"
-struct radius_msg *radius_msg_new(u8 code, u8 identifier);
+struct radius_msg * radius_msg_new(u8 code, u8 identifier);
void radius_msg_free(struct radius_msg *msg);
void radius_msg_dump(struct radius_msg *msg);
int radius_msg_finish(struct radius_msg *msg, const u8 *secret,
@@ -239,9 +239,9 @@ int radius_msg_finish_srv(struct radius_msg *msg, const u8 *secret,
size_t secret_len, const u8 *req_authenticator);
void radius_msg_finish_acct(struct radius_msg *msg, const u8 *secret,
size_t secret_len);
-struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
- const u8 *data, size_t data_len);
-struct radius_msg *radius_msg_parse(const u8 *data, size_t len);
+struct radius_attr_hdr * radius_msg_add_attr(struct radius_msg *msg, u8 type,
+ const u8 *data, size_t data_len);
+struct radius_msg * radius_msg_parse(const u8 *data, size_t len);
int radius_msg_add_eap(struct radius_msg *msg, const u8 *data,
size_t data_len);
u8 *radius_msg_get_eap(struct radius_msg *msg, size_t *len);
diff --git a/src/radius/radius_client.c b/src/radius/radius_client.c
index 4cb9c39..0ace8d1 100644
--- a/src/radius/radius_client.c
+++ b/src/radius/radius_client.c
@@ -247,7 +247,6 @@ static int radius_client_init_auth(struct radius_client_data *radius);
static void radius_client_msg_free(struct radius_msg_list *req)
{
radius_msg_free(req->msg);
- os_free(req->msg);
os_free(req);
}
@@ -526,7 +525,6 @@ static void radius_client_list_add(struct radius_client_data *radius,
/* No point in adding entries to retransmit queue since event
* loop has already been terminated. */
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -534,7 +532,6 @@ static void radius_client_list_add(struct radius_client_data *radius,
if (entry == NULL) {
printf("Failed to add RADIUS packet into retransmit list\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -802,7 +799,6 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
switch (res) {
case RADIUS_RX_PROCESSED:
radius_msg_free(msg);
- os_free(msg);
/* continue */
case RADIUS_RX_QUEUED:
radius_client_msg_free(req);
@@ -830,7 +826,6 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
fail:
radius_msg_free(msg);
- os_free(msg);
}
diff --git a/src/radius/radius_server.c b/src/radius/radius_server.c
index 635143f..54bfdac 100644
--- a/src/radius/radius_server.c
+++ b/src/radius/radius_server.c
@@ -359,15 +359,9 @@ static void radius_server_session_free(struct radius_server_data *data,
{
eloop_cancel_timeout(radius_server_session_timeout, data, sess);
eap_server_sm_deinit(sess->eap);
- if (sess->last_msg) {
- radius_msg_free(sess->last_msg);
- os_free(sess->last_msg);
- }
+ radius_msg_free(sess->last_msg);
os_free(sess->last_from_addr);
- if (sess->last_reply) {
- radius_msg_free(sess->last_reply);
- os_free(sess->last_reply);
- }
+ radius_msg_free(sess->last_reply);
os_free(sess);
data->num_sess--;
}
@@ -584,7 +578,6 @@ radius_server_encapsulate_eap(struct radius_server_data *data,
if (radius_msg_copy_attr(msg, request, RADIUS_ATTR_PROXY_STATE) < 0) {
RADIUS_DEBUG("Failed to copy Proxy-State attribute(s)");
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
@@ -629,7 +622,6 @@ static int radius_server_reject(struct radius_server_data *data,
if (radius_msg_copy_attr(msg, request, RADIUS_ATTR_PROXY_STATE) < 0) {
RADIUS_DEBUG("Failed to copy Proxy-State attribute(s)");
radius_msg_free(msg);
- os_free(msg);
return -1;
}
@@ -652,7 +644,6 @@ static int radius_server_reject(struct radius_server_data *data,
}
radius_msg_free(msg);
- os_free(msg);
return ret;
}
@@ -763,10 +754,7 @@ static int radius_server_request(struct radius_server_data *data,
RADIUS_DEBUG("No EAP data from the state machine, but eapFail "
"set");
} else if (eap_sm_method_pending(sess->eap)) {
- if (sess->last_msg) {
- radius_msg_free(sess->last_msg);
- os_free(sess->last_msg);
- }
+ radius_msg_free(sess->last_msg);
sess->last_msg = msg;
sess->last_from_port = from_port;
os_free(sess->last_from_addr);
@@ -813,10 +801,7 @@ static int radius_server_request(struct radius_server_data *data,
if (res < 0) {
perror("sendto[RADIUS SRV]");
}
- if (sess->last_reply) {
- radius_msg_free(sess->last_reply);
- os_free(sess->last_reply);
- }
+ radius_msg_free(sess->last_reply);
sess->last_reply = reply;
sess->last_from_port = from_port;
sess->last_identifier = msg->hdr->identifier;
@@ -944,10 +929,7 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
return; /* msg was stored with the session */
fail:
- if (msg) {
- radius_msg_free(msg);
- os_free(msg);
- }
+ radius_msg_free(msg);
os_free(buf);
}
@@ -1515,5 +1497,4 @@ void radius_server_eap_pending_cb(struct radius_server_data *data, void *ctx)
return; /* msg was stored with the session */
radius_msg_free(msg);
- os_free(msg);
}
diff --git a/wpa_supplicant/eapol_test.c b/wpa_supplicant/eapol_test.c
index 4bac935..a1710e2 100644
--- a/wpa_supplicant/eapol_test.c
+++ b/wpa_supplicant/eapol_test.c
@@ -283,7 +283,6 @@ static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
fail:
radius_msg_free(msg);
- os_free(msg);
}
@@ -440,10 +439,8 @@ static void test_eapol_clean(struct eapol_test_data *e,
radius_client_deinit(e->radius);
os_free(e->last_eap_radius);
- if (e->last_recv_radius) {
- radius_msg_free(e->last_recv_radius);
- os_free(e->last_recv_radius);
- }
+ radius_msg_free(e->last_recv_radius);
+ e->last_recv_radius = NULL;
os_free(e->eap_identity);
e->eap_identity = NULL;
eapol_sm_deinit(wpa_s->eapol);
@@ -694,11 +691,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
e->radius_identifier = -1;
wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
- if (e->last_recv_radius) {
- radius_msg_free(e->last_recv_radius);
- os_free(e->last_recv_radius);
- }
-
+ radius_msg_free(e->last_recv_radius);
e->last_recv_radius = msg;
switch (msg->hdr->code) {