Perform bitwise ops on unsigned types
[deliverable/lttng-ust.git] / liblttng-ust / lttng-filter-interpreter.c
index 1e7b12a5da4e0243ed1e00deb9b359b0569bb789..753880c3e269692072f9a6c416a22868e86e77ce 100644 (file)
@@ -1557,8 +1557,12 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
                                ret = -EINVAL;
                                goto end;
                        }
-
-                       res = (estack_bx_v >> estack_ax_v);
+                       /* Catch undefined behavior. */
+                       if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) {
+                               ret = -EINVAL;
+                               goto end;
+                       }
+                       res = ((uint64_t) estack_bx_v >> (uint32_t) estack_ax_v);
                        estack_pop(stack, top, ax, bx, ax_t, bx_t);
                        estack_ax_v = res;
                        estack_ax_t = REG_S64;
@@ -1574,8 +1578,12 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
                                ret = -EINVAL;
                                goto end;
                        }
-
-                       res = (estack_bx_v << estack_ax_v);
+                       /* Catch undefined behavior. */
+                       if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) {
+                               ret = -EINVAL;
+                               goto end;
+                       }
+                       res = ((uint64_t) estack_bx_v << (uint32_t) estack_ax_v);
                        estack_pop(stack, top, ax, bx, ax_t, bx_t);
                        estack_ax_v = res;
                        estack_ax_t = REG_S64;
@@ -1592,7 +1600,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
                                goto end;
                        }
 
-                       res = (estack_bx_v & estack_ax_v);
+                       res = ((uint64_t) estack_bx_v & (uint64_t) estack_ax_v);
                        estack_pop(stack, top, ax, bx, ax_t, bx_t);
                        estack_ax_v = res;
                        estack_ax_t = REG_S64;
@@ -1609,7 +1617,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
                                goto end;
                        }
 
-                       res = (estack_bx_v | estack_ax_v);
+                       res = ((uint64_t) estack_bx_v | (uint64_t) estack_ax_v);
                        estack_pop(stack, top, ax, bx, ax_t, bx_t);
                        estack_ax_v = res;
                        estack_ax_t = REG_S64;
@@ -1626,7 +1634,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
                                goto end;
                        }
 
-                       res = (estack_bx_v ^ estack_ax_v);
+                       res = ((uint64_t) estack_bx_v ^ (uint64_t) estack_ax_v);
                        estack_pop(stack, top, ax, bx, ax_t, bx_t);
                        estack_ax_v = res;
                        estack_ax_t = REG_S64;
@@ -1703,7 +1711,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
                                goto end;
                        }
 
-                       estack_ax_v = ~estack_ax_v;
+                       estack_ax_v = ~(uint64_t) estack_ax_v;
                        next_pc += sizeof(struct unary_op);
                        PO;
                }
This page took 0.024002 seconds and 5 git commands to generate.