# HG changeset patch # User Sebastien Decugis # Date 1353191330 -3600 # Node ID 9432ac55823ce81b639378118018a86cb98a9d17 # Parent 19a261c9a2e10377c2b8300afe50b29057c9003b Tentative fix for the parse_or_error function diff -r 19a261c9a2e1 -r 9432ac55823c include/freeDiameter/libfdproto.h --- a/include/freeDiameter/libfdproto.h Sat Nov 17 22:54:24 2012 +0100 +++ b/include/freeDiameter/libfdproto.h Sat Nov 17 23:28:50 2012 +0100 @@ -2523,7 +2523,7 @@ /* Parsing Error Information structure */ struct fd_pei { char * pei_errcode; /* name of the error code to use */ - struct avp * pei_avp; /* pointer to invalid or missing AVP (to be freed) */ + struct avp * pei_avp; /* pointer to invalid (in original message) or missing AVP (to be freed) */ char * pei_message; /* Overwrite default message if needed */ int pei_protoerr; /* do we set the 'E' bit in the error message ? */ }; diff -r 19a261c9a2e1 -r 9432ac55823c libfdcore/messages.c --- a/libfdcore/messages.c Sat Nov 17 22:54:24 2012 +0100 +++ b/libfdcore/messages.c Sat Nov 17 23:28:50 2012 +0100 @@ -233,11 +233,21 @@ /* Now add the optavp in a FailedAVP if provided */ if (optavp) { + struct avp * optavp_cpy = NULL; + struct avp_hdr *opt_hdr, *optcpy_hdr; + /* Create the Failed-AVP AVP */ CHECK_FCT( fd_msg_avp_new( dict_avp_FAVP, 0, &avp_FAVP ) ); - + + /* Create a new AVP with a copy of the data of the invalid or missing AVP */ + CHECK_FCT( fd_msg_avp_new( NULL, AVPFL_SET_BLANK_VALUE, &optavp_cpy) ); + + CHECK_FCT( fd_msg_avp_hdr(optavp, &opt_hdr) ); + CHECK_FCT( fd_msg_avp_hdr(optavp_cpy, &optcpy_hdr) ); + memcpy(optcpy_hdr, opt_hdr, sizeof(struct avp_hdr)); + /* Add the passed AVP inside it */ - CHECK_FCT( fd_msg_avp_add( avp_FAVP, MSG_BRW_LAST_CHILD, optavp ) ); + CHECK_FCT( fd_msg_avp_add( avp_FAVP, MSG_BRW_LAST_CHILD, optavp_cpy ) ); /* And add to the message */ CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_FAVP ) ); diff -r 19a261c9a2e1 -r 9432ac55823c libfdproto/messages.c --- a/libfdproto/messages.c Sat Nov 17 22:54:24 2012 +0100 +++ b/libfdproto/messages.c Sat Nov 17 23:28:50 2012 +0100 @@ -1778,6 +1778,7 @@ snprintf(error_message, sizeof(error_message), "I expected a size of %d for this AVP according to my dictionary", avp_value_sizes[dictdata.avp_basetype]); error_info->pei_message = error_message; } + avp->avp_model = NULL; return EBADMSG; } diff -r 19a261c9a2e1 -r 9432ac55823c tests/testmesg.c --- a/tests/testmesg.c Sat Nov 17 22:54:24 2012 +0100 +++ b/tests/testmesg.c Sat Nov 17 23:28:50 2012 +0100 @@ -766,14 +766,12 @@ CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); CHECK( EBADMSG, fd_msg_parse_or_error( &msg ) ); - /* Check the Failed-AVP is as expected */ + TODO("Check the Failed-AVP is as expected"); fd_msg_dump_walk(0, msg); /* reset */ CHECK( 0, fd_msg_free ( msg ) ); - - ASSERT(0); } #endif