Navigation



Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/messages.c

    r1248 r1305  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    232232                struct dict_avp_data dictdata;
    233233               
    234                 CHECK_FCT(  fd_dict_getval(model, &dictdata)  );
     234                CHECK_FCT_DO(  fd_dict_getval(model, &dictdata), { free(new); return __ret__; }  );
    235235       
    236236                new->avp_model = model;
     
    248248                new->avp_rawlen = (*avp)->avp_public.avp_len - GETAVPHDRSZ( (*avp)->avp_public.avp_flags );
    249249                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__; }  );
    251251                        memset(new->avp_rawdata, 0x00, new->avp_rawlen);
    252252                }
     
    286286                struct dict_object      *dictappl;
    287287               
    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__; }  );
    290290               
    291291                new->msg_model = model;
     
    294294
    295295                /* 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__; }  );
    297297                if (dictappl != NULL) {
    298298                        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__; }  );
    300300                        new->msg_public.msg_appl = appdata.application_id;
    301301                }
     
    365365               
    366366                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__; } );
    371371                val.os.data = sid;
    372372                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__; } );
    375375                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__; } );
    377377        }
    378378       
     
    383383                struct fd_list avpcpylist = FD_LIST_INITIALIZER(avpcpylist);
    384384               
    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__; } );
    386386                while (avp) {
    387387                        if ( (avp->avp_public.avp_code   == AC_PROXY_INFO)
     
    394394
    395395                                /* 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__; }  );
    399399
    400400                                /* 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__; } );
    402402                               
    403403                                /* 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__; } );
    405405
    406406                                /* Done for this AVP */
     
    411411                        }
    412412                        /* 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__; } );
    414414                }
    415415        }
     
    20372037{
    20382038        struct dict_avp_data dictdata;
     2039        struct dict_type_data derivedtypedata;
     2040        struct dict_object * avp_derived_type = NULL;
    20392041        uint8_t * source;
    20402042       
     
    22172219                        break;
    22182220       
     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                }
    22192248        }
    22202249       
Note: See TracChangeset for help on using the changeset viewer.