@@ -434,12 +434,12 @@ static int set_labels(struct log_to_metrics_ctx *ctx,
434434 mk_list_foreach (head , & f_ins -> properties ) {
435435 kv = mk_list_entry (head , struct flb_kv , _head );
436436
437- if (counter > ctx -> label_counter ) {
438- flb_plg_error (ctx -> ins , "internal label counter overflow" );
439- return -1 ;
440- }
441-
442437 if (strcasecmp (kv -> key , "label_field" ) == 0 ) {
438+ if (counter >= ctx -> label_counter ) {
439+ flb_plg_error (ctx -> ins , "internal label counter overflow" );
440+ return -1 ;
441+ }
442+
443443 /* name and accessor are the same string */
444444 ctx -> label_keys [counter ] = flb_strdup (kv -> val );
445445 if (!ctx -> label_keys [counter ]) {
@@ -454,6 +454,10 @@ static int set_labels(struct log_to_metrics_ctx *ctx,
454454 counter ++ ;
455455 }
456456 else if (strcasecmp (kv -> key , "add_label" ) == 0 ) {
457+ if (counter >= ctx -> label_counter ) {
458+ flb_plg_error (ctx -> ins , "internal label counter overflow" );
459+ return -1 ;
460+ }
457461 split = flb_utils_split (kv -> val , ' ' , 1 );
458462 if (mk_list_size (split ) != 2 ) {
459463 flb_plg_error (ctx -> ins , "invalid label, expected name and key" );
0 commit comments