@@ -441,8 +441,10 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
441441{
442442 int ret = 0 ;
443443 int i ;
444+ int has_le = CMT_FALSE ;
444445 size_t bucket_count ;
445446 size_t bucket_index ;
447+ size_t label_count = 0 ;
446448 double * buckets = NULL ;
447449 uint64_t * bucket_defaults = NULL ;
448450 double sum = 0 ;
@@ -488,14 +490,30 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
488490 "failed to allocate buckets" );
489491 goto end ;
490492 }
491- labels_without_le = calloc (context -> metric .label_count - 1 , sizeof (* labels_without_le ));
493+ for (i = 0 ; i < context -> metric .label_count ; i ++ ) {
494+ if (!strcmp (context -> metric .labels [i ], "le" )) {
495+ has_le = CMT_TRUE ;
496+ }
497+ else {
498+ label_count ++ ;
499+ }
500+ }
501+
502+ if (!has_le ) {
503+ ret = report_error (context ,
504+ CMT_DECODE_PROMETHEUS_SYNTAX_ERROR ,
505+ "missing histogram bucket \"le\" label" );
506+ goto end ;
507+ }
508+
509+ labels_without_le = calloc (label_count , sizeof (* labels_without_le ));
492510 if (!labels_without_le ) {
493511 ret = report_error (context ,
494512 CMT_DECODE_PROMETHEUS_CMT_CREATE_ERROR ,
495513 "failed to allocate labels_without_le" );
496514 goto end ;
497515 }
498- values_without_le = calloc (context -> metric . label_count - 1 , sizeof (* labels_without_le ));
516+ values_without_le = calloc (label_count , sizeof (* values_without_le ));
499517 if (!values_without_le ) {
500518 ret = report_error (context ,
501519 CMT_DECODE_PROMETHEUS_CMT_CREATE_ERROR ,
@@ -525,6 +543,13 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
525543 /* probably last bucket, which has "Inf" */
526544 break ;
527545 }
546+ if (!sample -> label_values [le_label_index ] ||
547+ sample -> label_values [le_label_index ][0 ] == '\0' ) {
548+ ret = report_error (context ,
549+ CMT_DECODE_PROMETHEUS_SYNTAX_ERROR ,
550+ "missing histogram bucket \"le\" value" );
551+ goto end ;
552+ }
528553 if (parse_double (sample -> label_values [le_label_index ],
529554 buckets + bucket_index )) {
530555 ret = report_error (context ,
0 commit comments