]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
sign promote the input only if the underlying data type is signed
authorAlan T. DeKok <aland@freeradius.org>
Tue, 7 Sep 2021 15:09:47 +0000 (11:09 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 7 Sep 2021 15:26:36 +0000 (11:26 -0400)
src/lib/util/value.c

index 2409aa39a02a46c999b1a315238da69d215546bd..cd49a53def7ff00b25ac5d4ddaf5af70a3c4adce 100644 (file)
@@ -2831,9 +2831,15 @@ static inline int fr_value_box_cast_integer_to_integer(UNUSED TALLOC_CTX *ctx, f
        }
 
        min = fr_value_box_integer_min[dst_type];
-       if ((min < 0) && SIGN_BIT_HIGH(tmp, len)) {
-               tmp = SIGN_PROMOTE(tmp, len);
-               if (((int64_t)tmp < min)) {
+
+       /*
+        *      Sign promote the input if the source type is
+        *      signed, and the high bit is set.
+        */
+       if (fr_value_box_integer_min[src->type] < 0) {
+               if (SIGN_BIT_HIGH(tmp, len)) tmp = SIGN_PROMOTE(tmp, len);
+
+               if ((int64_t)tmp < min) {
                        fr_strerror_printf("Invalid cast from %s to %s.  %"PRId64" "
                                           "outside value range %"PRId64"-%"PRIu64,
                                           fr_table_str_by_value(fr_value_box_type_table, src->type, "<INVALID>"),