Mercurial > hg > freeDiameter
diff libfdproto/messages.c @ 1300:3f1e79e1273e
Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sun, 30 Aug 2015 01:11:55 +0800 |
parents | 0f215b0dda5e |
children | 84a3c9c4b834 |
line wrap: on
line diff
--- a/libfdproto/messages.c Sat Jul 04 23:06:37 2015 +0800 +++ b/libfdproto/messages.c Sun Aug 30 01:11:55 2015 +0800 @@ -2036,6 +2036,8 @@ static int parsedict_do_avp(struct dictionary * dict, struct avp * avp, int mandatory, struct fd_pei *error_info) { struct dict_avp_data dictdata; + struct dict_type_data derivedtypedata; + struct dict_object * avp_derived_type = NULL; uint8_t * source; TRACE_ENTRY("%p %p %d %p", dict, avp, mandatory, error_info); @@ -2218,6 +2220,33 @@ } + /* Is there a derived type check function ? */ + CHECK_FCT ( fd_dict_search ( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &avp_derived_type, 0) ); + if (avp_derived_type) { + CHECK_FCT( fd_dict_getval(avp_derived_type, &derivedtypedata) ); + if (derivedtypedata.type_check != NULL) { + char * err; + int ret = (*derivedtypedata.type_check)( derivedtypedata.type_check_param, &avp->avp_storage, &err ); + + if (ret != 0) { + TRACE_DEBUG(INFO, "The AVP failed to pass the dictionary validation"); + if (error_info) { + error_info->pei_errcode = "DIAMETER_INVALID_AVP_VALUE"; + error_info->pei_avp = avp; + strncpy(error_message, err, sizeof(error_message)); + error_info->pei_message = error_message; + } else { + char * buf = NULL; + size_t buflen; + CHECK_MALLOC(fd_msg_dump_treeview(&buf, &buflen, NULL, avp, NULL, 0, 0)); + LOG_E("Invalid AVP: %s", buf); + free(buf); + } + return ret; /* should we just return EBADMSG? */ + } + } + } + /* The value is now set, so set the data pointer and return 0 */ avp->avp_public.avp_value = &avp->avp_storage; return 0;