Navigation


Changeset 1300:3f1e79e1273e in freeDiameter for libfdproto


Ignore:
Timestamp:
Aug 30, 2015, 2:11:55 AM (9 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.

Location:
libfdproto
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/dictionary_functions.c

    r1284 r1300  
    359359}
    360360
     361/* Check that a given AVP value contains all the characters from data in the same order */
     362static char error_message[80];
     363int fd_dictfct_CharInOS_check(void * data, union avp_value * val, char ** error_msg)
     364{
     365        char * inChar = data;
     366        char * inData = (char *)val->os.data;
     367        int i = 0;
     368        CHECK_PARAMS(data);
     369        while (*inChar != '\0') {
     370                while (i < val->os.len) {
     371                        if (*inChar == inData[i++]) {
     372                                inChar++;
     373                                break;
     374                        }
     375                }
     376                if (i >= val->os.len)
     377                        break;
     378        }
     379        if (*inChar == '\0')
     380                return 0;
     381       
     382        if (error_msg) {
     383                snprintf(error_message, sizeof(error_message), "Could not find '%c' in AVP", *inChar);
     384                *error_msg = error_message;
     385        }
     386        return EBADMSG;
     387}
  • libfdproto/messages.c

    r1298 r1300  
    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.