Mercurial > hg > waaad
changeset 367:e25e6117e6a1
Fixed problem of calling static function from a shared library
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Mon, 25 May 2009 10:40:11 +0900 |
parents | 4507804fc120 |
children | ccc9905c4525 |
files | extensions/radius_gw/radius.c extensions/radius_gw/rgw_msg.c |
diffstat | 2 files changed, 12 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/radius_gw/radius.c Fri May 22 18:18:56 2009 +0900 +++ b/extensions/radius_gw/radius.c Mon May 25 10:40:11 2009 +0900 @@ -3,7 +3,7 @@ * The content from this file comes directly from the hostap project. * It is redistributed under the terms of the BSD license, as allowed * by the original copyright reproduced bellow. - * In addition to this notide, only the #include directives have been modified. + * In addition to this notice, only the #include directives have been modified. */ #include "rg_common.h" /* Overwrite the printf definitions with our custom function */
--- a/extensions/radius_gw/rgw_msg.c Fri May 22 18:18:56 2009 +0900 +++ b/extensions/radius_gw/rgw_msg.c Mon May 25 10:40:11 2009 +0900 @@ -54,13 +54,10 @@ *msg = NULL; } -/* This function is derived from radius_msg_parse, but creates a rgw_radius_msg_meta structure instead */ +/* This function creates a rgw_radius_msg_meta structure after parsing a RADIUS buffer */ int rgw_msg_parse(unsigned char * buf, size_t len, struct rgw_radius_msg_meta ** msg) { - struct radius_hdr *hdr; - struct radius_attr_hdr *attr; - size_t msg_len; - unsigned char *pos, *end; + struct radius_msg * temp_msg = NULL; TRACE_ENTRY("%p %g %p", buf, len, msg); @@ -68,63 +65,19 @@ *msg = NULL; - if (len < sizeof(struct radius_hdr)) { - TRACE_DEBUG(INFO, "Buffer too short to contain a RADIUS message: %g", len); + /* Parse the RADIUS message */ + temp_msg = radius_msg_parse(buf, len); + if (temp_msg == NULL) { + TRACE_DEBUG(INFO, "Error parsing the RADIUS message, discarding"); return EINVAL; } - hdr = (struct radius_hdr *) buf; - - msg_len = ntohs(hdr->length); - if (msg_len < sizeof(*hdr) || msg_len > len) { - TRACE_DEBUG(INFO, "Invalid RADIUS message length: %g (buf: %g)", msg_len, len); - return EINVAL; - } - - if (msg_len < len) { - TRACE_DEBUG(INFO, "Received data after RADIUS message, ignoring %g bytes.", len - msg_len); - } - - /* Create the structure to store the parsing information */ - CHECK_MALLOC( *msg = malloc(sizeof(struct rgw_radius_msg_meta)) ); - memset(*msg, 0, sizeof(struct rgw_radius_msg_meta)); + /* Now alloc space for the meta-data */ + CHECK_MALLOC( *msg = realloc(temp_msg, sizeof(struct rgw_radius_msg_meta)) ); - if (radius_msg_initialize(&(*msg)->radius, msg_len)) { - TRACE_DEBUG(INFO, "Error in radius_msg_initialize"); - free(*msg); - return ENOMEM; /* the most likely error... */ - } - - memcpy((*msg)->radius.buf, buf, msg_len); - (*msg)->radius.buf_size = (*msg)->radius.buf_used = msg_len; - - /* parse attributes */ - pos = (unsigned char *) ((*msg)->radius.hdr + 1); - end = (*msg)->radius.buf + (*msg)->radius.buf_used; - while (pos < end) { - if ((size_t) (end - pos) < sizeof(*attr)) { - TRACE_DEBUG(INFO, "Invalid RADIUS message size (rem: %d)", (end - pos)); - rgw_msg_free(msg); - return EINVAL; - } - - attr = (struct radius_attr_hdr *) pos; - - if (pos + attr->length > end || attr->length < sizeof(*attr)) { - TRACE_DEBUG(INFO, "Invalid RADIUS message or attribute size (attr: %hhd, rem: %d)", attr->length, (end - pos)); - rgw_msg_free(msg); - return EINVAL; - } - - if (radius_msg_add_attr_to_array(&(*msg)->radius, attr)) { - TRACE_DEBUG(INFO, "Error in radius_msg_add_attr_to_array"); - rgw_msg_free(msg); - return ENOMEM; - } - - pos += attr->length; - } - + /* Clear memory after the parsed data */ + memset( &(*msg)->radius + 1, 0, sizeof(struct rgw_radius_msg_meta) - sizeof(struct radius_msg) ); + return 0; }