Fix: validate return value of bt_ctf_field_get_type_id
[babeltrace.git] / formats / ctf / ir / fields.c
index 3ca57bb017ba097bce5517fd17735a1cbf08c168..105dd7a1dbe737317a3114c08a9f617710c55c8a 100644 (file)
@@ -928,8 +928,8 @@ int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *field,
        }
 
        size = integer_type->declaration.len;
-       min_value = -((int64_t)1 << (size - 1));
-       max_value = ((int64_t)1 << (size - 1)) - 1;
+       min_value = -(1ULL << (size - 1));
+       max_value = (1ULL << (size - 1)) - 1;
        if (value < min_value || value > max_value) {
                ret = -1;
                goto end;
@@ -994,7 +994,7 @@ int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *field,
        }
 
        size = integer_type->declaration.len;
-       max_value = (size == 64) ? UINT64_MAX : ((uint64_t)1 << size) - 1;
+       max_value = (size == 64) ? UINT64_MAX : ((uint64_t) 1 << size) - 1;
        if (value > max_value) {
                ret = -1;
                goto end;
@@ -2339,12 +2339,19 @@ void bt_ctf_field_sequence_freeze(struct bt_ctf_field *field)
 BT_HIDDEN
 void bt_ctf_field_freeze(struct bt_ctf_field *field)
 {
+       enum bt_ctf_type_id type_id;
+
        if (!field) {
                goto end;
        }
 
-       field_freeze_funcs[bt_ctf_field_get_type_id(field)](field);
+       type_id = bt_ctf_field_get_type_id(field);
+       if (type_id <= BT_CTF_TYPE_ID_UNKNOWN ||
+                       type_id >= BT_CTF_NR_TYPE_IDS) {
+               goto end;
+       }
 
+       field_freeze_funcs[type_id](field);
 end:
        return;
 }
This page took 0.025247 seconds and 4 git commands to generate.