Changes in libfdproto/messages.c [1248:c9a160b815ea:1305:84a3c9c4b834] in freeDiameter
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdproto/messages.c
r1248 r1305 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 232 232 struct dict_avp_data dictdata; 233 233 234 CHECK_FCT ( fd_dict_getval(model, &dictdata));234 CHECK_FCT_DO( fd_dict_getval(model, &dictdata), { free(new); return __ret__; } ); 235 235 236 236 new->avp_model = model; … … 248 248 new->avp_rawlen = (*avp)->avp_public.avp_len - GETAVPHDRSZ( (*avp)->avp_public.avp_flags ); 249 249 if (new->avp_rawlen) { 250 CHECK_MALLOC ( new->avp_rawdata = malloc(new->avp_rawlen));250 CHECK_MALLOC_DO( new->avp_rawdata = malloc(new->avp_rawlen), { free(new); return __ret__; } ); 251 251 memset(new->avp_rawdata, 0x00, new->avp_rawlen); 252 252 } … … 286 286 struct dict_object *dictappl; 287 287 288 CHECK_FCT ( fd_dict_getdict(model, &dict));289 CHECK_FCT ( fd_dict_getval(model, &dictdata));288 CHECK_FCT_DO( fd_dict_getdict(model, &dict), { free(new); return __ret__; } ); 289 CHECK_FCT_DO( fd_dict_getval(model, &dictdata), { free(new); return __ret__; } ); 290 290 291 291 new->msg_model = model; … … 294 294 295 295 /* Initialize application from the parent, if any */ 296 CHECK_FCT ( fd_dict_search( dict, DICT_APPLICATION, APPLICATION_OF_COMMAND, model, &dictappl, 0));296 CHECK_FCT_DO( fd_dict_search( dict, DICT_APPLICATION, APPLICATION_OF_COMMAND, model, &dictappl, 0), { free(new); return __ret__; } ); 297 297 if (dictappl != NULL) { 298 298 struct dict_application_data appdata; 299 CHECK_FCT ( fd_dict_getval(dictappl, &appdata));299 CHECK_FCT_DO( fd_dict_getval(dictappl, &appdata), { free(new); return __ret__; } ); 300 300 new->msg_public.msg_appl = appdata.application_id; 301 301 } … … 365 365 366 366 if (!sess_id_avp) { 367 CHECK_FCT ( fd_dict_search( dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sess_id_avp, ENOENT));368 } 369 CHECK_FCT ( fd_sess_getsid ( sess, &sid, &sidlen ));370 CHECK_FCT ( fd_msg_avp_new ( sess_id_avp, 0, &avp ));367 CHECK_FCT_DO( fd_dict_search( dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sess_id_avp, ENOENT), { free(ans); return __ret__; } ); 368 } 369 CHECK_FCT_DO( fd_sess_getsid ( sess, &sid, &sidlen ), { free(ans); return __ret__; } ); 370 CHECK_FCT_DO( fd_msg_avp_new ( sess_id_avp, 0, &avp ), { free(ans); return __ret__; } ); 371 371 val.os.data = sid; 372 372 val.os.len = sidlen; 373 CHECK_FCT ( fd_msg_avp_setvalue( avp, &val ));374 CHECK_FCT ( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ));373 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), { free(avp); free(ans); return __ret__; } ); 374 CHECK_FCT_DO( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ), { free(avp); free(ans); return __ret__; } ); 375 375 ans->msg_sess = sess; 376 CHECK_FCT ( fd_sess_ref_msg(sess));376 CHECK_FCT_DO( fd_sess_ref_msg(sess), { free(ans); return __ret__; } ); 377 377 } 378 378 … … 383 383 struct fd_list avpcpylist = FD_LIST_INITIALIZER(avpcpylist); 384 384 385 CHECK_FCT ( fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL));385 CHECK_FCT_DO( fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL) , { free(ans); return __ret__; } ); 386 386 while (avp) { 387 387 if ( (avp->avp_public.avp_code == AC_PROXY_INFO) … … 394 394 395 395 /* Create a buffer with the content of the AVP. This is easier than going through the list */ 396 CHECK_FCT ( fd_msg_update_length(avp));397 CHECK_MALLOC ( buf = malloc(avp->avp_public.avp_len));398 CHECK_FCT ( bufferize_avp(buf, avp->avp_public.avp_len, &offset, avp));396 CHECK_FCT_DO( fd_msg_update_length(avp), { free(ans); return __ret__; } ); 397 CHECK_MALLOC_DO( buf = malloc(avp->avp_public.avp_len), { free(ans); return __ret__; } ); 398 CHECK_FCT_DO( bufferize_avp(buf, avp->avp_public.avp_len, &offset, avp), { free(buf); free(ans); return __ret__; } ); 399 399 400 400 /* Now we parse this buffer to create a copy AVP */ 401 CHECK_FCT ( parsebuf_list(buf, avp->avp_public.avp_len, &avpcpylist));401 CHECK_FCT_DO( parsebuf_list(buf, avp->avp_public.avp_len, &avpcpylist), { free(buf); free(ans); return __ret__; } ); 402 402 403 403 /* Parse dictionary objects now to remove the dependency on the buffer */ 404 CHECK_FCT ( parsedict_do_chain(dict, &avpcpylist, 0, &pei));404 CHECK_FCT_DO( parsedict_do_chain(dict, &avpcpylist, 0, &pei), { /* leaking the avpcpylist -- this should never happen anyway */ free(buf); free(ans); return __ret__; } ); 405 405 406 406 /* Done for this AVP */ … … 411 411 } 412 412 /* move to next AVP in the message, we can have several Proxy-Info instances */ 413 CHECK_FCT ( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL));413 CHECK_FCT_DO( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL), { free(ans); return __ret__; } ); 414 414 } 415 415 } … … 2037 2037 { 2038 2038 struct dict_avp_data dictdata; 2039 struct dict_type_data derivedtypedata; 2040 struct dict_object * avp_derived_type = NULL; 2039 2041 uint8_t * source; 2040 2042 … … 2217 2219 break; 2218 2220 2221 } 2222 2223 /* Is there a derived type check function ? */ 2224 CHECK_FCT ( fd_dict_search ( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &avp_derived_type, 0) ); 2225 if (avp_derived_type) { 2226 CHECK_FCT( fd_dict_getval(avp_derived_type, &derivedtypedata) ); 2227 if (derivedtypedata.type_check != NULL) { 2228 char * err; 2229 int ret = (*derivedtypedata.type_check)( derivedtypedata.type_check_param, &avp->avp_storage, &err ); 2230 2231 if (ret != 0) { 2232 TRACE_DEBUG(INFO, "The AVP failed to pass the dictionary validation"); 2233 if (error_info) { 2234 error_info->pei_errcode = "DIAMETER_INVALID_AVP_VALUE"; 2235 error_info->pei_avp = avp; 2236 strncpy(error_message, err, sizeof(error_message)); 2237 error_info->pei_message = error_message; 2238 } else { 2239 char * buf = NULL; 2240 size_t buflen; 2241 CHECK_MALLOC(fd_msg_dump_treeview(&buf, &buflen, NULL, avp, NULL, 0, 0)); 2242 LOG_E("Invalid AVP: %s", buf); 2243 free(buf); 2244 } 2245 return ret; /* should we just return EBADMSG? */ 2246 } 2247 } 2219 2248 } 2220 2249
Note: See TracChangeset
for help on using the changeset viewer.