code
stringlengths
14
2.05k
label
int64
0
1
programming_language
stringclasses
7 values
cwe_id
stringlengths
6
14
cwe_name
stringlengths
5
98
description
stringlengths
36
379
url
stringlengths
36
48
label_name
stringclasses
2 values
size_t fp_size_str(const fp_t a, unsigned int radix) { bn_t t; size_t digits = 0; bn_null(t); RLC_TRY { bn_new(t); fp_prime_back(t, a); digits = bn_size_str(t, radix); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } return digits; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp_read_str(fp_t a, const char *str, size_t len, unsigned int radix) { bn_t t; bn_null(t); RLC_TRY { bn_new(t); bn_read_str(t, str, len, radix); if (bn_is_zero(t)) { fp_zero(a); } else { if (t->used == 1) { fp_prime_conv_dig(a, t->dp[0]); if (bn_sign(t) == RLC_NEG) { fp_neg(a, a); } } else { fp_prime_conv(a, t); } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp_set_bit(fp_t a, size_t bit, int value) { int d; dig_t mask; RLC_RIP(bit, d, bit); mask = (dig_t)1 << bit; if (value == 1) { a[d] |= mask; } else { a[d] &= ~mask; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int fp_get_bit(const fp_t a, size_t bit) { int d; RLC_RIP(bit, d, bit); return (a[d] >> bit) & 1; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
size_t fp_bits(const fp_t a) { int i = RLC_FP_DIGS - 1; while (i >= 0 && a[i] == 0) { i--; } if (i > 0) { return (i << RLC_DIG_LOG) + util_bits_dig(a[i]); } else { return util_bits_dig(a[0]); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp_write_bin(uint8_t *bin, size_t len, const fp_t a) { bn_t t; bn_null(t); if (len != RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } RLC_TRY { bn_new(t); fp_prime_back(t, a); bn_write_bin(bin, len, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp48_exp_cyc_sps(fp48_t c, const fp48_t a, const int *b, size_t len, int sign) { size_t i, j, k, w = len; fp48_t t, *u = RLC_ALLOCA(fp48_t, w); if (len == 0) { RLC_FREE(u); fp48_set_dig(c, 1); return; } fp48_null(t); RLC_TRY { if (u == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < w; i++) { fp48_null(u[i]); fp48_new(u[i]); } fp48_new(t); fp48_copy(t, a); if (b[0] == 0) { for (j = 0, i = 1; i < len; i++) { k = (b[i] < 0 ? -b[i] : b[i]); for (; j < k; j++) { fp48_sqr_pck(t, t); } if (b[i] < 0) { fp48_inv_cyc(u[i - 1], t); } else { fp48_copy(u[i - 1], t); } } fp48_back_cyc_sim(u, u, w - 1); fp48_copy(c, a); for (i = 0; i < w - 1; i++) { fp48_mul(c, c, u[i]); } } else { for (j = 0, i = 0; i < len; i++) { k = (b[i] < 0 ? -b[i] : b[i]); for (; j < k; j++) { fp48_sqr_pck(t, t); } if (b[i] < 0) { fp48_inv_cyc(u[i], t); } else { fp48_copy(u[i], t); } } fp48_back_cyc_sim(u, u, w); fp48_copy(c, u[0]); for (i = 1; i < w; i++) { fp48_mul(c, c, u[i]); } } if (sign == RLC_NEG) { fp48_inv_cyc(c, c); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < w; i++) { fp48_free(u[i]); } fp48_free(t); RLC_FREE(u); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp8_exp_cyc(fp8_t c, const fp8_t a, const bn_t b) { fp8_t r, s, t[1 << (FP_WIDTH - 2)]; int8_t naf[RLC_FP_BITS + 1], *k; size_t l; if (bn_is_zero(b)) { return fp8_set_dig(c, 1); } fp8_null(r); fp8_null(s); RLC_TRY { fp8_new(r); fp8_new(s); for (int i = 0; i < (1 << (FP_WIDTH - 2)); i ++) { fp8_null(t[i]); fp8_new(t[i]); } #if FP_WIDTH > 2 fp8_sqr_cyc(t[0], a); fp8_mul(t[1], t[0], a); for (int i = 2; i < (1 << (FP_WIDTH - 2)); i++) { fp8_mul(t[i], t[i - 1], t[0]); } #endif fp8_copy(t[0], a); l = RLC_FP_BITS + 1; fp8_set_dig(r, 1); bn_rec_naf(naf, &l, b, FP_WIDTH); k = naf + l - 1; for (int i = l - 1; i >= 0; i--, k--) { fp8_sqr_cyc(r, r); if (*k > 0) { fp8_mul(r, r, t[*k / 2]); } if (*k < 0) { fp8_inv_cyc(s, t[-*k / 2]); fp8_mul(r, r, s); } } if (bn_sign(b) == RLC_NEG) { fp8_inv_cyc(c, r); } else { fp8_copy(c, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp8_free(r); fp8_free(s); for (int i = 0; i < (1 << (FP_WIDTH - 2)); i++) { fp8_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp2_exp_cyc(fp2_t c, const fp2_t a, const bn_t b) { fp2_t r, s, t[1 << (FP_WIDTH - 2)]; int8_t naf[RLC_FP_BITS + 1], *k; size_t l; if (bn_is_zero(b)) { return fp2_set_dig(c, 1); } fp2_null(r); fp2_null(s); RLC_TRY { fp2_new(r); fp2_new(s); for (int i = 0; i < (1 << (FP_WIDTH - 2)); i ++) { fp2_null(t[i]); fp2_new(t[i]); } #if FP_WIDTH > 2 fp2_sqr(t[0], a); fp2_mul(t[1], t[0], a); for (int i = 2; i < (1 << (FP_WIDTH - 2)); i++) { fp2_mul(t[i], t[i - 1], t[0]); } #endif fp2_copy(t[0], a); l = RLC_FP_BITS + 1; fp2_set_dig(r, 1); bn_rec_naf(naf, &l, b, FP_WIDTH); k = naf + l - 1; for (int i = l - 1; i >= 0; i--, k--) { fp2_sqr(r, r); if (*k > 0) { fp2_mul(r, r, t[*k / 2]); } if (*k < 0) { fp2_inv_cyc(s, t[-*k / 2]); fp2_mul(r, r, s); } } if (bn_sign(b) == RLC_NEG) { fp2_inv_cyc(c, r); } else { fp2_copy(c, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp2_free(r); fp2_free(s); for (int i = 0; i < (1 << (FP_WIDTH - 2)); i++) { fp2_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp12_exp_cyc_sps(fp12_t c, const fp12_t a, const int *b, size_t len, int sign) { size_t i, j, k, w = len; fp12_t t, *u = RLC_ALLOCA(fp12_t, w); if (len == 0) { RLC_FREE(u); fp12_set_dig(c, 1); return; } fp12_null(t); RLC_TRY { if (u == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < w; i++) { fp12_null(u[i]); fp12_new(u[i]); } fp12_new(t); fp12_copy(t, a); if (b[0] == 0) { for (j = 0, i = 1; i < len; i++) { k = (b[i] < 0 ? -b[i] : b[i]); for (; j < k; j++) { fp12_sqr_pck(t, t); } if (b[i] < 0) { fp12_inv_cyc(u[i - 1], t); } else { fp12_copy(u[i - 1], t); } } fp12_back_cyc_sim(u, u, w - 1); fp12_copy(c, a); for (i = 0; i < w - 1; i++) { fp12_mul(c, c, u[i]); } } else { for (j = 0, i = 0; i < len; i++) { k = (b[i] < 0 ? -b[i] : b[i]); for (; j < k; j++) { fp12_sqr_pck(t, t); } if (b[i] < 0) { fp12_inv_cyc(u[i], t); } else { fp12_copy(u[i], t); } } fp12_back_cyc_sim(u, u, w); fp12_copy(c, u[0]); for (i = 1; i < w; i++) { fp12_mul(c, c, u[i]); } } if (sign == RLC_NEG) { fp12_inv_cyc(c, c); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < w; i++) { fp12_free(u[i]); } fp12_free(t); RLC_FREE(u); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp24_exp_cyc_sim(fp24_t e, const fp24_t a, const bn_t b, const fp24_t c, const bn_t d) { int n0, n1; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], *_k, *_m; fp24_t r, t0[1 << (EP_WIDTH - 2)]; fp24_t s, t1[1 << (EP_WIDTH - 2)]; size_t l, l0, l1; if (bn_is_zero(b)) { return fp24_exp_cyc(e, c, d); } if (bn_is_zero(d)) { return fp24_exp_cyc(e, a, b); } fp24_null(r); fp24_null(s); RLC_TRY { fp24_new(r); fp24_new(s); for (int i = 0; i < (1 << (FP_WIDTH - 2)); i ++) { fp24_null(t0[i]); fp24_null(t1[i]); fp24_new(t0[i]); fp24_new(t1[i]); } #if FP_WIDTH > 2 fp24_sqr(t0[0], a); fp24_mul(t0[1], t0[0], a); for (int i = 2; i < (1 << (FP_WIDTH - 2)); i++) { fp24_mul(t0[i], t0[i - 1], t0[0]); } fp24_sqr(t1[0], c); fp24_mul(t1[1], t1[0], c); for (int i = 2; i < (1 << (FP_WIDTH - 2)); i++) { fp24_mul(t1[i], t1[i - 1], t1[0]); } #endif fp24_copy(t0[0], a); fp24_copy(t1[0], c); l0 = l1 = RLC_FP_BITS + 1; bn_rec_naf(naf0, &l0, b, FP_WIDTH); bn_rec_naf(naf1, &l1, d, FP_WIDTH); l = RLC_MAX(l0, l1); if (bn_sign(b) == RLC_NEG) { for (size_t i = 0; i < l0; i++) { naf0[i] = -naf0[i]; } } if (bn_sign(d) == RLC_NEG) { for (size_t i = 0; i < l1; i++) { naf1[i] = -naf1[i]; } } _k = naf0 + l - 1; _m = naf1 + l - 1; fp24_set_dig(r, 1); for (int i = l - 1; i >= 0; i--, _k--, _m--) { fp24_sqr(r, r); n0 = *_k; n1 = *_m; if (n0 > 0) { fp24_mul(r, r, t0[n0 / 2]); } if (n0 < 0) { fp24_inv_cyc(s, t0[-n0 / 2]); fp24_mul(r, r, s); } if (n1 > 0) { fp24_mul(r, r, t1[n1 / 2]); } if (n1 < 0) { fp24_inv_cyc(s, t1[-n1 / 2]); fp24_mul(r, r, s); } } fp24_copy(e, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp24_free(r); fp24_free(s); for (int i = 0; i < (1 << (FP_WIDTH - 2)); i++) { fp24_free(t0[i]); fp24_free(t1[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp24_exp_cyc_sps(fp24_t c, const fp24_t a, const int *b, size_t len, int sign) { size_t i, j, k, w = len; fp24_t t, *u = RLC_ALLOCA(fp24_t, w); if (len == 0) { RLC_FREE(u); fp24_set_dig(c, 1); return; } fp24_null(t); RLC_TRY { if (u == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < w; i++) { fp24_null(u[i]); fp24_new(u[i]); } fp24_new(t); fp24_copy(t, a); if (b[0] == 0) { for (j = 0, i = 1; i < len; i++) { k = (b[i] < 0 ? -b[i] : b[i]); for (; j < k; j++) { fp24_sqr_pck(t, t); } if (b[i] < 0) { fp24_inv_cyc(u[i - 1], t); } else { fp24_copy(u[i - 1], t); } } fp24_back_cyc_sim(u, u, w - 1); fp24_copy(c, a); for (i = 0; i < w - 1; i++) { fp24_mul(c, c, u[i]); } } else { for (j = 0, i = 0; i < len; i++) { k = (b[i] < 0 ? -b[i] : b[i]); for (; j < k; j++) { fp24_sqr_pck(t, t); } if (b[i] < 0) { fp24_inv_cyc(u[i], t); } else { fp24_copy(u[i], t); } } fp24_back_cyc_sim(u, u, w); fp24_copy(c, u[0]); for (i = 1; i < w; i++) { fp24_mul(c, c, u[i]); } } if (sign == RLC_NEG) { fp24_inv_cyc(c, c); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < w; i++) { fp24_free(u[i]); } fp24_free(t); RLC_FREE(u); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp2_exp_cyc_sim(fp2_t e, const fp2_t a, const bn_t b, const fp2_t c, const bn_t d) { int n0, n1; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], *_k, *_m; fp2_t r, t0[1 << (EP_WIDTH - 2)]; fp2_t s, t1[1 << (EP_WIDTH - 2)]; size_t l, l0, l1; if (bn_is_zero(b)) { return fp2_exp_cyc(e, c, d); } if (bn_is_zero(d)) { return fp2_exp_cyc(e, a, b); } fp2_null(r); fp2_null(s); RLC_TRY { fp2_new(r); fp2_new(s); for (int i = 0; i < (1 << (FP_WIDTH - 2)); i ++) { fp2_null(t0[i]); fp2_null(t1[i]); fp2_new(t0[i]); fp2_new(t1[i]); } #if FP_WIDTH > 2 fp2_sqr(t0[0], a); fp2_mul(t0[1], t0[0], a); for (int i = 2; i < (1 << (FP_WIDTH - 2)); i++) { fp2_mul(t0[i], t0[i - 1], t0[0]); } fp2_sqr(t1[0], c); fp2_mul(t1[1], t1[0], c); for (int i = 2; i < (1 << (FP_WIDTH - 2)); i++) { fp2_mul(t1[i], t1[i - 1], t1[0]); } #endif fp2_copy(t0[0], a); fp2_copy(t1[0], c); l0 = l1 = RLC_FP_BITS + 1; bn_rec_naf(naf0, &l0, b, FP_WIDTH); bn_rec_naf(naf1, &l1, d, FP_WIDTH); l = RLC_MAX(l0, l1); if (bn_sign(b) == RLC_NEG) { for (size_t i = 0; i < l0; i++) { naf0[i] = -naf0[i]; } } if (bn_sign(d) == RLC_NEG) { for (size_t i = 0; i < l1; i++) { naf1[i] = -naf1[i]; } } _k = naf0 + l - 1; _m = naf1 + l - 1; fp2_set_dig(r, 1); for (int i = l - 1; i >= 0; i--, _k--, _m--) { fp2_sqr(r, r); n0 = *_k; n1 = *_m; if (n0 > 0) { fp2_mul(r, r, t0[n0 / 2]); } if (n0 < 0) { fp2_inv_cyc(s, t0[-n0 / 2]); fp2_mul(r, r, s); } if (n1 > 0) { fp2_mul(r, r, t1[n1 / 2]); } if (n1 < 0) { fp2_inv_cyc(s, t1[-n1 / 2]); fp2_mul(r, r, s); } } fp2_copy(e, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp2_free(r); fp2_free(s); for (int i = 0; i < (1 << (FP_WIDTH - 2)); i++) { fp2_free(t0[i]); fp2_free(t1[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp54_exp_cyc_sps(fp54_t c, const fp54_t a, const int *b, size_t len, int sign) { size_t i, j, k, w = len; fp54_t t, *u = RLC_ALLOCA(fp54_t, w); if (len == 0) { RLC_FREE(u); fp54_set_dig(c, 1); return; } fp54_null(t); RLC_TRY { if (u == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < w; i++) { fp54_null(u[i]); fp54_new(u[i]); } fp54_new(t); fp54_copy(t, a); if (b[0] == 0) { for (j = 0, i = 1; i < len; i++) { k = (b[i] < 0 ? -b[i] : b[i]); for (; j < k; j++) { fp54_sqr_pck(t, t); } if (b[i] < 0) { fp54_inv_cyc(u[i - 1], t); } else { fp54_copy(u[i - 1], t); } } fp54_back_cyc_sim(u, u, w - 1); fp54_copy(c, a); for (i = 0; i < w - 1; i++) { fp54_mul(c, c, u[i]); } } else { for (j = 0, i = 0; i < len; i++) { k = (b[i] < 0 ? -b[i] : b[i]); for (; j < k; j++) { fp54_sqr_pck(t, t); } if (b[i] < 0) { fp54_inv_cyc(u[i], t); } else { fp54_copy(u[i], t); } } fp54_back_cyc_sim(u, u, w); fp54_copy(c, u[0]); for (i = 1; i < w; i++) { fp54_mul(c, c, u[i]); } } if (sign == RLC_NEG) { fp54_inv_cyc(c, c); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < w; i++) { fp54_free(u[i]); } fp54_free(t); RLC_FREE(u); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp12_exp_dig(fp12_t c, const fp12_t a, dig_t b) { bn_t _b; fp12_t t, v; int8_t u, naf[RLC_DIG + 1]; size_t l; if (b == 0) { fp12_set_dig(c, 1); return; } bn_null(_b); fp12_null(t); fp12_null(v); RLC_TRY { bn_new(_b); fp12_new(t); fp12_new(v); fp12_copy(t, a); if (fp12_test_cyc(a)) { fp12_inv_cyc(v, a); bn_set_dig(_b, b); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _b, 2); for (int i = bn_bits(_b) - 2; i >= 0; i--) { fp12_sqr_cyc(t, t); u = naf[i]; if (u > 0) { fp12_mul(t, t, a); } else if (u < 0) { fp12_mul(t, t, v); } } } else { for (int i = util_bits_dig(b) - 2; i >= 0; i--) { fp12_sqr(t, t); if (b & ((dig_t)1 << i)) { fp12_mul(t, t, a); } } } fp12_copy(c, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(_b); fp12_free(t); fp12_free(v); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp24_exp_dig(fp24_t c, const fp24_t a, dig_t b) { bn_t _b; fp24_t t, v; int8_t u, naf[RLC_DIG + 1]; size_t l; if (b == 0) { fp24_set_dig(c, 1); return; } bn_null(_b); fp24_null(t); fp24_null(v); RLC_TRY { bn_new(_b); fp24_new(t); fp24_new(v); fp24_copy(t, a); if (fp24_test_cyc(a)) { fp24_inv_cyc(v, a); bn_set_dig(_b, b); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _b, 2); for (int i = bn_bits(_b) - 2; i >= 0; i--) { fp24_sqr_cyc(t, t); u = naf[i]; if (u > 0) { fp24_mul(t, t, a); } else if (u < 0) { fp24_mul(t, t, v); } } } else { for (int i = util_bits_dig(b) - 2; i >= 0; i--) { fp24_sqr(t, t); if (b & ((dig_t)1 << i)) { fp24_mul(t, t, a); } } } fp24_copy(c, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(_b); fp24_free(t); fp24_free(v); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp48_exp_dig(fp48_t c, const fp48_t a, dig_t b) { bn_t _b; fp48_t t, v; int8_t u, naf[RLC_DIG + 1]; size_t l; if (b == 0) { fp48_set_dig(c, 1); return; } bn_null(_b); fp48_null(t); fp48_null(v); RLC_TRY { bn_new(_b); fp48_new(t); fp48_new(v); fp48_copy(t, a); if (fp48_test_cyc(a)) { fp48_inv_cyc(v, a); bn_set_dig(_b, b); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _b, 2); for (int i = bn_bits(_b) - 2; i >= 0; i--) { fp48_sqr_cyc(t, t); u = naf[i]; if (u > 0) { fp48_mul(t, t, a); } else if (u < 0) { fp48_mul(t, t, v); } } } else { for (int i = util_bits_dig(b) - 2; i >= 0; i--) { fp48_sqr(t, t); if (b & ((dig_t)1 << i)) { fp48_mul(t, t, a); } } } fp48_copy(c, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(_b); fp48_free(t); fp48_free(v); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp54_exp_dig(fp54_t c, const fp54_t a, dig_t b) { bn_t _b; fp54_t t, v; int8_t u, naf[RLC_DIG + 1]; size_t l; if (b == 0) { fp54_set_dig(c, 1); return; } bn_null(_b); fp54_null(t); fp54_null(v); RLC_TRY { bn_new(_b); fp54_new(t); fp54_new(v); fp54_copy(t, a); if (fp54_test_cyc(a)) { fp54_inv_cyc(v, a); bn_set_dig(_b, b); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _b, 2); for (int i = bn_bits(_b) - 2; i >= 0; i--) { fp54_sqr_cyc(t, t); u = naf[i]; if (u > 0) { fp54_mul(t, t, a); } else if (u < 0) { fp54_mul(t, t, v); } } } else { for (int i = util_bits_dig(b) - 2; i >= 0; i--) { fp54_sqr(t, t); if (b & ((dig_t)1 << i)) { fp54_mul(t, t, a); } } } fp54_copy(c, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(_b); fp54_free(t); fp54_free(v); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp6_read_bin(fp6_t a, const uint8_t *bin, size_t len) { if (len != 6 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp2_read_bin(a[0], bin, 2 * RLC_FP_BYTES); fp2_read_bin(a[1], bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); fp2_read_bin(a[2], bin + 4 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp2_write_bin(uint8_t *bin, size_t len, const fp2_t a, int pack) { fp2_t t; fp2_null(t); RLC_TRY { fp2_new(t); if (pack && fp2_test_cyc(a)) { if (len < RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { fp2_pck(t, a); fp_write_bin(bin, RLC_FP_BYTES, t[0]); bin[RLC_FP_BYTES] = fp_get_bit(t[1], 0); } } else { if (len < 2 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } else { fp_write_bin(bin, RLC_FP_BYTES, a[0]); fp_write_bin(bin + RLC_FP_BYTES, RLC_FP_BYTES, a[1]); } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp2_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp4_read_bin(fp4_t a, const uint8_t *bin, size_t len) { if (len != 4 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp2_read_bin(a[0], bin, 2 * RLC_FP_BYTES); fp2_read_bin(a[1], bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp3_write_bin(uint8_t *bin, size_t len, const fp3_t a) { if (len != 3 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp_write_bin(bin, RLC_FP_BYTES, a[0]); fp_write_bin(bin + RLC_FP_BYTES, RLC_FP_BYTES, a[1]); fp_write_bin(bin + 2 * RLC_FP_BYTES, RLC_FP_BYTES, a[2]); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp8_read_bin(fp8_t a, const uint8_t *bin, size_t len) { if (len != 8 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp4_read_bin(a[0], bin, 4 * RLC_FP_BYTES); fp4_read_bin(a[1], bin + 4 * RLC_FP_BYTES, 4 * RLC_FP_BYTES); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp24_write_bin(uint8_t *bin, size_t len, const fp24_t a, int pack) { fp24_t t; fp24_null(t); RLC_TRY { fp24_new(t); if (pack) { if (len != 16 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp24_pck(t, a); fp4_write_bin(bin, 4 * RLC_FP_BYTES, a[1][0]); fp4_write_bin(bin + 4 * RLC_FP_BYTES, 4 * RLC_FP_BYTES, a[1][1]); fp4_write_bin(bin + 8 * RLC_FP_BYTES, 4 * RLC_FP_BYTES, a[2][0]); fp4_write_bin(bin + 12 * RLC_FP_BYTES, 4 * RLC_FP_BYTES, a[2][1]); } else { if (len != 24 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp8_write_bin(bin, 8 * RLC_FP_BYTES, a[0]); fp8_write_bin(bin + 8 * RLC_FP_BYTES, 8 * RLC_FP_BYTES, a[1]); fp8_write_bin(bin + 16 * RLC_FP_BYTES, 8 * RLC_FP_BYTES, a[2]); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp24_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp48_read_bin(fp48_t a, const uint8_t *bin, size_t len) { if (len != 32 * RLC_FP_BYTES && len != 48 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == 32 * RLC_FP_BYTES) { fp8_zero(a[0][0]); fp8_read_bin(a[0][1], bin, 8 * RLC_FP_BYTES); fp8_read_bin(a[0][2], bin + 8 * RLC_FP_BYTES, 8 * RLC_FP_BYTES); fp8_read_bin(a[1][0], bin + 16 * RLC_FP_BYTES, 8 * RLC_FP_BYTES); fp8_zero(a[1][1]); fp8_read_bin(a[1][2], bin + 24 * RLC_FP_BYTES, 8 * RLC_FP_BYTES); fp48_back_cyc(a, a); } if (len == 48 * RLC_FP_BYTES) { fp24_read_bin(a[0], bin, 24 * RLC_FP_BYTES); fp24_read_bin(a[1], bin + 24 * RLC_FP_BYTES, 24 * RLC_FP_BYTES); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp4_write_bin(uint8_t *bin, size_t len, const fp4_t a) { if (len != 4 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp2_write_bin(bin, 2 * RLC_FP_BYTES, a[0], 0); fp2_write_bin(bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[1], 0); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp6_write_bin(uint8_t *bin, size_t len, const fp6_t a) { if (len != 6 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp2_write_bin(bin, 2 * RLC_FP_BYTES, a[0], 0); fp2_write_bin(bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[1], 0); fp2_write_bin(bin + 4 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[2], 0); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp24_read_bin(fp24_t a, const uint8_t *bin, size_t len) { if (len != 16 * RLC_FP_BYTES && len != 24 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == 16 * RLC_FP_BYTES) { fp4_zero(a[0][0]); fp4_zero(a[0][1]); fp4_read_bin(a[1][0], bin, 4 * RLC_FP_BYTES); fp4_read_bin(a[1][1], bin + 4 * RLC_FP_BYTES, 4 * RLC_FP_BYTES); fp4_read_bin(a[2][0], bin + 8 * RLC_FP_BYTES, 4 * RLC_FP_BYTES); fp4_read_bin(a[2][1], bin + 12 * RLC_FP_BYTES, 4 * RLC_FP_BYTES); fp24_back_cyc(a, a); } if (len == 24 * RLC_FP_BYTES) { fp8_read_bin(a[0], bin, 8 * RLC_FP_BYTES); fp8_read_bin(a[1], bin + 8 * RLC_FP_BYTES, 8 * RLC_FP_BYTES); fp8_read_bin(a[2], bin + 16 * RLC_FP_BYTES, 8 * RLC_FP_BYTES); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp2_read_bin(fp2_t a, const uint8_t *bin, size_t len) { if (len != RLC_FP_BYTES + 1 && len != 2 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == RLC_FP_BYTES + 1) { fp_read_bin(a[0], bin, RLC_FP_BYTES); fp_zero(a[1]); fp_set_bit(a[1], 0, bin[RLC_FP_BYTES]); fp2_upk(a, a); } if (len == 2 * RLC_FP_BYTES) { fp_read_bin(a[0], bin, RLC_FP_BYTES); fp_read_bin(a[1], bin + RLC_FP_BYTES, RLC_FP_BYTES); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp54_write_bin(uint8_t *bin, size_t len, const fp54_t a, int pack) { fp54_t t; fp54_null(t); RLC_TRY { fp54_new(t); if (pack) { if (len != 36 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp54_pck(t, a); fp9_write_bin(bin, 9 * RLC_FP_BYTES, a[1][0]); fp9_write_bin(bin + 9 * RLC_FP_BYTES, 9 * RLC_FP_BYTES, a[1][1]); fp9_write_bin(bin + 18 * RLC_FP_BYTES, 9 * RLC_FP_BYTES, a[2][0]); fp9_write_bin(bin + 27 * RLC_FP_BYTES, 9 * RLC_FP_BYTES, a[2][1]); } else { if (len != 54 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp18_write_bin(bin, 18 * RLC_FP_BYTES, a[0]); fp18_write_bin(bin + 18 * RLC_FP_BYTES, 18 * RLC_FP_BYTES, a[1]); fp18_write_bin(bin + 36 * RLC_FP_BYTES, 18 * RLC_FP_BYTES, a[2]); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp54_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp54_read_bin(fp54_t a, const uint8_t *bin, size_t len) { if (len != 36 * RLC_FP_BYTES && len != 54 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == 36 * RLC_FP_BYTES) { fp9_zero(a[0][0]); fp9_zero(a[0][1]); fp9_read_bin(a[1][0], bin, 9 * RLC_FP_BYTES); fp9_read_bin(a[1][1], bin + 9 * RLC_FP_BYTES, 9 * RLC_FP_BYTES); fp9_read_bin(a[2][0], bin + 18 * RLC_FP_BYTES, 9 * RLC_FP_BYTES); fp9_read_bin(a[2][1], bin + 27 * RLC_FP_BYTES, 9 * RLC_FP_BYTES); fp54_back_cyc(a, a); } if (len == 54 * RLC_FP_BYTES) { fp18_read_bin(a[0], bin, 18 * RLC_FP_BYTES); fp18_read_bin(a[1], bin + 18 * RLC_FP_BYTES, 18 * RLC_FP_BYTES); fp18_read_bin(a[2], bin + 36 * RLC_FP_BYTES, 18 * RLC_FP_BYTES); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp3_read_bin(fp3_t a, const uint8_t *bin, size_t len) { if (len != 3 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp_read_bin(a[0], bin, RLC_FP_BYTES); fp_read_bin(a[1], bin + RLC_FP_BYTES, RLC_FP_BYTES); fp_read_bin(a[2], bin + 2 * RLC_FP_BYTES, RLC_FP_BYTES); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp8_write_bin(uint8_t *bin, size_t len, const fp8_t a) { if (len != 8 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp4_write_bin(bin, 4 * RLC_FP_BYTES, a[0]); fp4_write_bin(bin + 4 * RLC_FP_BYTES, 4 * RLC_FP_BYTES, a[1]); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp9_read_bin(fp9_t a, const uint8_t *bin, size_t len) { if (len != 9 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp3_read_bin(a[0], bin, 3 * RLC_FP_BYTES); fp3_read_bin(a[1], bin + 3 * RLC_FP_BYTES, 3 * RLC_FP_BYTES); fp3_read_bin(a[2], bin + 6 * RLC_FP_BYTES, 3 * RLC_FP_BYTES); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp12_read_bin(fp12_t a, const uint8_t *bin, size_t len) { if (len != 8 * RLC_FP_BYTES && len != 12 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == 8 * RLC_FP_BYTES) { fp2_zero(a[0][0]); fp2_read_bin(a[0][1], bin, 2 * RLC_FP_BYTES); fp2_read_bin(a[0][2], bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); fp2_read_bin(a[1][0], bin + 4 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); fp2_zero(a[1][1]); fp2_read_bin(a[1][2], bin + 6 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); fp12_back_cyc(a, a); } if (len == 12 * RLC_FP_BYTES) { fp6_read_bin(a[0], bin, 6 * RLC_FP_BYTES); fp6_read_bin(a[1], bin + 6 * RLC_FP_BYTES, 6 * RLC_FP_BYTES); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp12_write_bin(uint8_t *bin, size_t len, const fp12_t a, int pack) { fp12_t t; fp12_null(t); RLC_TRY { fp12_new(t); if (pack) { if (len != 8 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp12_pck(t, a); fp2_write_bin(bin, 2 * RLC_FP_BYTES, a[0][1], 0); fp2_write_bin(bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[0][2], 0); fp2_write_bin(bin + 4 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[1][0], 0); fp2_write_bin(bin + 6 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[1][2], 0); } else { if (len != 12 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp6_write_bin(bin, 6 * RLC_FP_BYTES, a[0]); fp6_write_bin(bin + 6 * RLC_FP_BYTES, 6 * RLC_FP_BYTES, a[1]); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp12_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp9_write_bin(uint8_t *bin, size_t len, const fp9_t a) { if (len != 9 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp3_write_bin(bin, 3 * RLC_FP_BYTES, a[0]); fp3_write_bin(bin + 3 * RLC_FP_BYTES, 3 * RLC_FP_BYTES, a[1]); fp3_write_bin(bin + 6 * RLC_FP_BYTES, 3 * RLC_FP_BYTES, a[2]); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp48_write_bin(uint8_t *bin, size_t len, const fp48_t a, int pack) { fp48_t t; fp48_null(t); RLC_TRY { fp48_new(t); if (pack) { if (len != 32 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp48_pck(t, a); fp8_write_bin(bin, 8 * RLC_FP_BYTES, a[0][1]); fp8_write_bin(bin + 8 * RLC_FP_BYTES, 8 * RLC_FP_BYTES, a[0][2]); fp8_write_bin(bin + 16 * RLC_FP_BYTES, 8 * RLC_FP_BYTES, a[1][0]); fp8_write_bin(bin + 24 * RLC_FP_BYTES, 8 * RLC_FP_BYTES, a[1][2]); } else { if (len != 48 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp24_write_bin(bin, 24 * RLC_FP_BYTES, a[0], 0); fp24_write_bin(bin + 24 * RLC_FP_BYTES, 24 * RLC_FP_BYTES, a[1], 0); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp48_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp18_read_bin(fp18_t a, const uint8_t *bin, size_t len) { if (len != 18 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp9_read_bin(a[0], bin, 9 * RLC_FP_BYTES); fp9_read_bin(a[1], bin + 9 * RLC_FP_BYTES, 9 * RLC_FP_BYTES); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp18_write_bin(uint8_t *bin, size_t len, const fp18_t a) { if (len != 18 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp9_write_bin(bin, 9 * RLC_FP_BYTES, a[0]); fp9_write_bin(bin + 9 * RLC_FP_BYTES, 9 * RLC_FP_BYTES, a[1]); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_map_b2s256(uint8_t *hash, const uint8_t *msg, size_t len) { memset(hash, 0, RLC_MD_LEN_B2S256); blake2s(hash, RLC_MD_LEN_B2S256, msg, len, NULL, 0); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_map_b2s160(uint8_t *hash, const uint8_t *msg, size_t len) { memset(hash, 0, RLC_MD_LEN_B2S160); blake2s(hash, RLC_MD_LEN_B2S160, msg, len, NULL, 0); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_hmac(uint8_t *mac, const uint8_t *in, size_t in_len, const uint8_t *key, size_t key_len) { #if MD_MAP == SH224 || MD_MAP == SH256 || MD_MAP == B2S160 || MD_MAP == B2S256 #define block_size 64 #elif MD_MAP == SH384 || MD_MAP == SH512 #define block_size 128 #endif uint8_t opad[block_size + RLC_MD_LEN]; uint8_t *ipad = RLC_ALLOCA(uint8_t, block_size + in_len); uint8_t _key[RLC_MAX(RLC_MD_LEN, block_size)]; if (ipad == NULL) { RLC_THROW(ERR_NO_MEMORY); return; } if (key_len > block_size) { md_map(_key, key, key_len); key = _key; key_len = RLC_MD_LEN; } if (key_len <= block_size) { memcpy(_key, key, key_len); memset(_key + key_len, 0, block_size - key_len); key = _key; } for (int i = 0; i < block_size; i++) { opad[i] = 0x5C ^ key[i]; ipad[i] = 0x36 ^ key[i]; } memcpy(ipad + block_size, in, in_len); md_map(opad + block_size, ipad, block_size + in_len); md_map(mac, opad, block_size + RLC_MD_LEN); RLC_FREE(ipad); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_kdf(uint8_t *key, size_t key_len, const uint8_t *in, size_t in_len) { uint32_t i, j, d; uint8_t* buffer = RLC_ALLOCA(uint8_t, in_len + sizeof(uint32_t)); uint8_t* t = RLC_ALLOCA(uint8_t, key_len + RLC_MD_LEN); if (buffer == NULL || t == NULL) { RLC_FREE(buffer); RLC_FREE(t); RLC_THROW(ERR_NO_MEMORY); return; } /* d = ceil(kLen/hLen). */ d = RLC_CEIL(key_len, RLC_MD_LEN); memcpy(buffer, in, in_len); for (i = 1; i <= d; i++) { j = util_conv_big(i); /* c = integer_to_string(c, 4). */ memcpy(buffer + in_len, &j, sizeof(uint32_t)); /* t = t || hash(z || c). */ md_map(t + (i - 1) * RLC_MD_LEN, buffer, in_len + sizeof(uint32_t)); } memcpy(key, t, key_len); RLC_FREE(buffer); RLC_FREE(t); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_mgf(uint8_t *key, size_t key_len, const uint8_t *in, size_t in_len) { uint32_t i, j, d; uint8_t *buffer = RLC_ALLOCA(uint8_t, in_len + sizeof(uint32_t)); uint8_t *t = RLC_ALLOCA(uint8_t, key_len + RLC_MD_LEN); if (buffer == NULL || t == NULL) { RLC_FREE(buffer); RLC_FREE(t); RLC_THROW(ERR_NO_MEMORY); return; } /* d = ceil(kLen/hLen). */ d = RLC_CEIL(key_len, RLC_MD_LEN); memcpy(buffer, in, in_len); for (i = 0; i < d; i++) { j = util_conv_big(i); /* c = integer_to_string(c, 4). */ memcpy(buffer + in_len, &j, sizeof(uint32_t)); /* t = t || hash(z || c). */ md_map(t + i * RLC_MD_LEN, buffer, in_len + sizeof(uint32_t)); } memcpy(key, t, key_len); RLC_FREE(buffer); RLC_FREE(t); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_map_sh224(uint8_t *hash, const uint8_t *msg, size_t len) { SHA224Context ctx; if (SHA224Reset(&ctx) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } if (SHA224Input(&ctx, msg, len) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } if (SHA224Result(&ctx, hash) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_map_sh256(uint8_t *hash, const uint8_t *msg, size_t len) { SHA256Context ctx; if (SHA256Reset(&ctx) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } if (SHA256Input(&ctx, msg, len) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } if (SHA256Result(&ctx, hash) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_map_sh384(uint8_t *hash, const uint8_t *msg, size_t len) { SHA384Context ctx; if (SHA384Reset(&ctx) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } if (SHA384Input(&ctx, msg, len) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } if (SHA384Result(&ctx, hash) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void md_map_sh512(uint8_t *hash, const uint8_t *msg, size_t len) { SHA512Context ctx; if (SHA512Reset(&ctx) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } if (SHA512Input(&ctx, msg, len) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } if (SHA512Result(&ctx, hash) != shaSuccess) { RLC_THROW(ERR_NO_VALID); return; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void pp_mil_k12(fp12_t r, ep2_t *t, ep2_t *q, ep_t *p, int m, bn_t a) { fp12_t l; ep_t *_p = RLC_ALLOCA(ep_t, m); ep2_t *_q = RLC_ALLOCA(ep2_t, m); size_t len = bn_bits(a) + 1; int i, j; int8_t s[RLC_FP_BITS + 1]; if (m == 0) { return; } fp12_null(l); RLC_TRY { fp12_new(l); if (_p == NULL || _q == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (j = 0; j < m; j++) { ep_null(_p[j]); ep2_null(_q[j]); ep_new(_p[j]); ep2_new(_q[j]); ep2_copy(t[j], q[j]); ep2_neg(_q[j], q[j]); #if EP_ADD == BASIC ep_neg(_p[j], p[j]); #else fp_add(_p[j]->x, p[j]->x, p[j]->x); fp_add(_p[j]->x, _p[j]->x, p[j]->x); fp_neg(_p[j]->y, p[j]->y); #endif } fp12_zero(l); bn_rec_naf(s, &len, a, 2); pp_dbl_k12(r, t[0], t[0], _p[0]); for (j = 1; j < m; j++) { pp_dbl_k12(l, t[j], t[j], _p[j]); fp12_mul_dxs(r, r, l); } if (s[len - 2] > 0) { for (j = 0; j < m; j++) { pp_add_k12(l, t[j], q[j], p[j]); fp12_mul_dxs(r, r, l); } } if (s[len - 2] < 0) { for (j = 0; j < m; j++) { pp_add_k12(l, t[j], _q[j], p[j]); fp12_mul_dxs(r, r, l); } } for (i = len - 3; i >= 0; i--) { fp12_sqr(r, r); for (j = 0; j < m; j++) { pp_dbl_k12(l, t[j], t[j], _p[j]); fp12_mul_dxs(r, r, l); if (s[i] > 0) { pp_add_k12(l, t[j], q[j], p[j]); fp12_mul_dxs(r, r, l); } if (s[i] < 0) { pp_add_k12(l, t[j], _q[j], p[j]); fp12_mul_dxs(r, r, l); } } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp12_free(l); for (j = 0; j < m; j++) { ep_free(_p[j]); ep2_free(_q[j]); } RLC_FREE(_p); RLC_FREE(_q); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void pp_mil_k24(fp24_t r, ep4_t *t, ep4_t *q, ep_t *p, int m, bn_t a) { fp24_t l; ep_t *_p = RLC_ALLOCA(ep_t, m); ep4_t *_q = RLC_ALLOCA(ep4_t, m); size_t len = bn_bits(a) + 1; int i, j; int8_t s[RLC_FP_BITS + 1]; if (m == 0) { return; } fp24_null(l); RLC_TRY { fp24_new(l); if (_p == NULL || _q == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (j = 0; j < m; j++) { ep_null(_p[j]); ep4_null(_q[j]); ep_new(_p[j]); ep4_new(_q[j]); ep4_copy(t[j], q[j]); ep4_neg(_q[j], q[j]); #if EP_ADD == BASIC ep_neg(_p[j], p[j]); #else fp_add(_p[j]->x, p[j]->x, p[j]->x); fp_add(_p[j]->x, _p[j]->x, p[j]->x); fp_neg(_p[j]->y, p[j]->y); #endif } fp24_zero(l); bn_rec_naf(s, &len, a, 2); pp_dbl_k24(r, t[0], t[0], _p[0]); for (j = 1; j < m; j++) { pp_dbl_k24(l, t[j], t[j], _p[j]); fp24_mul_dxs(r, r, l); } if (s[len - 2] > 0) { for (j = 0; j < m; j++) { pp_add_k24(l, t[j], q[j], p[j]); fp24_mul_dxs(r, r, l); } } if (s[len - 2] < 0) { for (j = 0; j < m; j++) { pp_add_k24(l, t[j], _q[j], p[j]); fp24_mul_dxs(r, r, l); } } for (i = len - 3; i >= 0; i--) { fp24_sqr(r, r); for (j = 0; j < m; j++) { pp_dbl_k24(l, t[j], t[j], _p[j]); fp24_mul_dxs(r, r, l); if (s[i] > 0) { pp_add_k24(l, t[j], q[j], p[j]); fp24_mul_dxs(r, r, l); } if (s[i] < 0) { pp_add_k24(l, t[j], _q[j], p[j]); fp24_mul_dxs(r, r, l); } } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp24_free(l); for (j = 0; j < m; j++) { ep_free(_p[j]); ep4_free(_q[j]); } RLC_FREE(_p); RLC_FREE(_q); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void pp_mil_k48(fp48_t r, const fp8_t qx, const fp8_t qy, const ep_t p, const bn_t a) { fp48_t l; ep_t _p; fp8_t rx, ry, rz, qn; size_t len = bn_bits(a) + 1; int i; int8_t s[RLC_FP_BITS + 1]; fp48_null(l); ep_null(_p); fp8_null(rx); fp8_null(ry); fp8_null(rz); fp8_null(qn); RLC_TRY { fp48_new(l); ep_new(_p); fp8_new(rx); fp8_new(ry); fp8_new(rz); fp8_new(qn); fp48_zero(l); fp8_copy(rx, qx); fp8_copy(ry, qy); fp8_set_dig(rz, 1); #if EP_ADD == BASIC ep_neg(_p, p); #else fp_add(_p->x, p->x, p->x); fp_add(_p->x, _p->x, p->x); fp_neg(_p->y, p->y); #endif fp8_neg(qn, qy); bn_rec_naf(s, &len, a, 2); for (i = len - 2; i >= 0; i--) { fp48_sqr(r, r); pp_dbl_k48(l, rx, ry, rz, _p); fp48_mul_dxs(r, r, l); if (s[i] > 0) { pp_add_k48(l, rx, ry, rz, qx, qy, p); fp48_mul_dxs(r, r, l); } if (s[i] < 0) { pp_add_k48(l, rx, ry, rz, qx, qn, p); fp48_mul_dxs(r, r, l); } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp48_free(l); ep_free(_p); fp8_free(rx); fp8_free(ry); fp8_free(rz); fp8_free(qn); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void pp_mil_k8(fp8_t r, ep2_t *t, ep2_t *q, ep_t *p, int m, bn_t a) { fp8_t l; ep_t *_p = RLC_ALLOCA(ep_t, m); ep2_t *_q = RLC_ALLOCA(ep2_t, m); size_t len = bn_bits(a) + 1; int i, j; int8_t s[RLC_FP_BITS + 1]; if (m == 0) { return; } fp8_null(l); RLC_TRY { fp8_new(l); if (_p == NULL || _q == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (j = 0; j < m; j++) { ep_null(_p[j]); ep2_null(_q[j]); ep_new(_p[j]); ep2_new(_q[j]); ep2_copy(t[j], q[j]); ep2_neg(_q[j], q[j]); #if EP_ADD == BASIC ep_neg(_p[j], p[j]); #else fp_neg(_p[j]->x, p[j]->x); fp_copy(_p[j]->y, p[j]->y); #endif } fp8_zero(l); bn_rec_naf(s, &len, a, 2); for (i = len - 2; i >= 0; i--) { fp8_sqr(r, r); for (j = 0; j < m; j++) { pp_dbl_k8(l, t[j], t[j], _p[j]); fp8_mul(r, r, l); if (s[i] > 0) { pp_add_k8(l, t[j], q[j], _p[j]); fp8_mul_dxs(r, r, l); } if (s[i] < 0) { pp_add_k8(l, t[j], _q[j], _p[j]); fp8_mul_dxs(r, r, l); } } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp8_free(l); for (j = 0; j < m; j++) { ep_free(_p[j]); ep2_free(_q[j]); } RLC_FREE(_p); RLC_FREE(_q); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int rand_check(uint8_t *buf, size_t size) { int count = 0; for (int i = 1; i < size; i++) { if (buf[i] == buf[i - 1]) { count++; } else { count = 0; } } if (count > RAND_REP) { return RLC_ERR; } return RLC_OK; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static int rand_add(uint8_t *state, uint8_t *hash, size_t size) { int carry = 0; for (int i = size - 1; i >= 0; i--) { /* Make sure carries are detected. */ int16_t s; s = (state[i] + hash[i] + carry); state[i] = s & 0xFF; carry = s >> 8; } return carry; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void rand_bytes(uint8_t *buf, size_t size) { uint8_t hash[RLC_MD_LEN]; int carry, len = (RLC_RAND_SIZE - 1)/2; ctx_t *ctx = core_get(); if (sizeof(int) > 2 && size > (1 << 16)) { RLC_THROW(ERR_NO_VALID); return; } /* buf = hash_gen(size) */ rand_gen(buf, size); /* H = hash(03 || V) */ ctx->rand[0] = 0x3; md_map(hash, ctx->rand, 1 + len); /* V = V + H + C + reseed_counter. */ rand_add(ctx->rand + 1, ctx->rand + 1 + len, len); carry = rand_add(ctx->rand + 1 + (len - RLC_MD_LEN), hash, RLC_MD_LEN); rand_inc(ctx->rand, len - RLC_MD_LEN + 1, carry); rand_inc(ctx->rand, len + 1, ctx->counter); ctx->counter = ctx->counter + 1; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void rand_seed(uint8_t *buf, size_t size) { ctx_t *ctx = core_get(); size_t len = (RLC_RAND_SIZE - 1) / 2; if (size <= 0) { RLC_THROW(ERR_NO_VALID); return; } if (sizeof(int) > 4 && size > (1 << 32)) { RLC_THROW(ERR_NO_VALID); return; } ctx->rand[0] = 0x0; if (ctx->seeded == 0) { /* V = hash_df(seed). */ rand_hash(ctx->rand + 1, len, buf, size); /* C = hash_df(00 || V). */ rand_hash(ctx->rand + 1 + len, len, ctx->rand, len + 1); } else { /* V = hash_df(01 || V || seed). */ int tmp_size = 1 + len + size; uint8_t* tmp = RLC_ALLOCA(uint8_t, tmp_size); if (tmp == NULL) { RLC_THROW(ERR_NO_MEMORY); return; } tmp[0] = 1; memcpy(tmp + 1, ctx->rand + 1, len); memcpy(tmp + 1 + len, buf, size); rand_hash(ctx->rand + 1, len, tmp, tmp_size); /* C = hash_df(00 || V). */ rand_hash(ctx->rand + 1 + len, len, ctx->rand, len + 1); RLC_FREE(tmp); } ctx->counter = ctx->seeded = 1; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void rand_gen(uint8_t *out, size_t out_len) { int m = RLC_CEIL(out_len, RLC_MD_LEN); uint8_t hash[RLC_MD_LEN], data[(RLC_RAND_SIZE - 1)/2]; ctx_t *ctx = core_get(); /* data = V */ memcpy(data, ctx->rand + 1, (RLC_RAND_SIZE - 1)/2); for (int i = 0; i < m; i++) { /* w_i = Hash(data) */ md_map(hash, data, sizeof(data)); /* W = W || w_i */ memcpy(out, hash, RLC_MIN(RLC_MD_LEN, out_len)); out += RLC_MD_LEN; out_len -= RLC_MD_LEN; /* data = data + 1 mod 2^b. */ rand_inc(data, (RLC_RAND_SIZE - 1)/2, 1); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static int rand_inc(uint8_t *data, size_t size, int digit) { int carry = digit; for (int i = size - 1; i >= 0; i--) { int16_t s; s = (data[i] + carry); data[i] = s & 0xFF; carry = s >> 8; } return carry; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void rand_hash(uint8_t *out, size_t out_len, uint8_t *in, size_t in_len) { uint32_t j = util_conv_big(8 * out_len); size_t len = RLC_CEIL(out_len, RLC_MD_LEN); uint8_t* buf = RLC_ALLOCA(uint8_t, 1 + sizeof(uint32_t) + in_len); uint8_t hash[RLC_MD_LEN]; if (buf == NULL) { RLC_THROW(ERR_NO_MEMORY); return; } buf[0] = 1; memcpy(buf + 1, &j, sizeof(uint32_t)); memcpy(buf + 1 + sizeof(uint32_t), in, in_len); for (int i = 0; i < len; i++) { /* h = Hash(counter || bits_to_return || input_string) */ md_map(hash, buf, 1 + sizeof(uint32_t) + in_len); /* temp = temp || h */ memcpy(out, hash, RLC_MIN(RLC_MD_LEN, out_len)); out += RLC_MD_LEN; out_len -= RLC_MD_LEN; /* counter = counter + 1 */ buf[0]++; } RLC_FREE(buf); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
size_t util_bits_dig(dig_t a) { return RLC_DIG - arch_lzcnt(a); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static int square_root(void) { size_t bits; bn_t a, b, c; int code = RLC_ERR; bn_null(a); bn_null(b); bn_null(c); RLC_TRY { bn_new(a); bn_new(b); bn_new(c); TEST_ONCE("square root extraction is correct") { for (bits = 0; bits < RLC_BN_BITS / 2; bits++) { bn_rand(a, RLC_POS, bits); bn_sqr(c, a); bn_srt(b, c); TEST_ASSERT(bn_cmp(a, b) == RLC_EQ, end); } for (bits = 0; bits < RLC_BN_BITS; bits++) { bn_rand(a, RLC_POS, bits); bn_srt(b, a); bn_sqr(c, b); TEST_ASSERT(bn_cmp(c, a) != RLC_GT, end); } } TEST_END; TEST_ONCE("square root of powers of 2 is correct") { for (bits = 0; bits < RLC_BN_BITS / 2; bits++) { bn_set_2b(a, bits); bn_sqr(c, a); bn_srt(b, c); TEST_ASSERT(bn_cmp(a, b) == RLC_EQ, end); } } TEST_END; } RLC_CATCH_ANY { RLC_ERROR(end); } code = RLC_OK; end: bn_free(a); bn_free(b); bn_free(c); return code; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int util(void) { int code = RLC_ERR; gt_t a, b, c; uint8_t bin[24 * RLC_PC_BYTES]; gt_null(a); gt_null(b); gt_null(c); RLC_TRY { gt_new(a); gt_new(b); gt_new(c); TEST_CASE("comparison is consistent") { gt_rand(a); gt_rand(b); TEST_ASSERT(gt_cmp(a, b) != RLC_EQ, end); } TEST_END; TEST_CASE("copy and comparison are consistent") { gt_rand(a); gt_rand(b); gt_rand(c); if (gt_cmp(a, c) != RLC_EQ) { gt_copy(c, a); TEST_ASSERT(gt_cmp(c, a) == RLC_EQ, end); } if (gt_cmp(b, c) != RLC_EQ) { gt_copy(c, b); TEST_ASSERT(gt_cmp(b, c) == RLC_EQ, end); } } TEST_END; TEST_CASE("inversion and comparison are consistent") { gt_rand(a); gt_inv(b, a); TEST_ASSERT(gt_cmp(a, b) != RLC_EQ, end); } TEST_END; TEST_CASE ("assignment to random/infinity and comparison are consistent") { gt_rand(a); gt_set_unity(c); TEST_ASSERT(gt_cmp(a, c) != RLC_EQ, end); TEST_ASSERT(gt_cmp(c, a) != RLC_EQ, end); } TEST_END; TEST_CASE("assignment to unity and unity test are consistent") { gt_set_unity(a); TEST_ASSERT(gt_is_unity(a), end); } TEST_END; } RLC_CATCH_ANY { util_print("FATAL ERROR!\n"); RLC_ERROR(end); } code = RLC_OK; end: gt_free(a); gt_free(b); gt_free(c); return code; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static int test(void) { uint8_t out[64]; size_t len = sizeof(out) / 2, code = RLC_ERR; TEST_ONCE("rdrand hardware generator is non-trivial") { memset(out, 0, 2 * len); rand_bytes(out, len); /* This fails with negligible probability. */ TEST_ASSERT(memcmp(out, out + len, len) != 0, end); } TEST_END; code = RLC_OK; end: return code; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static int restrictedFile(const char *filename) { char *stripped_filename; RAII_VAR(char *, path, NULL, ast_free); RAII_VAR(char *, real_path, NULL, ast_free); if (live_dangerously) { return 0; } stripped_filename = ast_strip(ast_strdupa(filename)); /* If the file path starts with '/', don't prepend ast_config_AST_CONFIG_DIR */ if (stripped_filename[0] == '/') { real_path = realpath(stripped_filename, NULL); } else { if (ast_asprintf(&path, "%s/%s", ast_config_AST_CONFIG_DIR, stripped_filename) == -1) { return -1; } real_path = realpath(path, NULL); } if (!real_path) { return -1; } if (!ast_begins_with(real_path, ast_config_AST_CONFIG_DIR)) { return 1; } return 0; }
1
C
CWE-22
Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
https://cwe.mitre.org/data/definitions/22.html
safe
Suite *cjose_jwe_suite() { Suite *suite = suite_create("jwe"); TCase *tc_jwe = tcase_create("core"); tcase_set_timeout(tc_jwe, 120.0); tcase_add_test(tc_jwe, test_cjose_jwe_node_jose_encrypt_self_decrypt); tcase_add_test(tc_jwe, test_cjose_jwe_self_encrypt_self_decrypt); tcase_add_test(tc_jwe, test_cjose_jwe_self_encrypt_self_decrypt_iv); tcase_add_test(tc_jwe, test_cjose_jwe_self_encrypt_self_decrypt_short); tcase_add_test(tc_jwe, test_cjose_jwe_self_encrypt_self_decrypt_empty); tcase_add_test(tc_jwe, test_cjose_jwe_self_encrypt_self_decrypt_large); tcase_add_test(tc_jwe, test_cjose_jwe_self_encrypt_self_decrypt_many); tcase_add_test(tc_jwe, test_cjose_jwe_decrypt_aes); tcase_add_test(tc_jwe, test_cjose_jwe_decrypt_aes_gcm); tcase_add_test(tc_jwe, test_cjose_jwe_decrypt_rsa); tcase_add_test(tc_jwe, test_cjose_jwe_encrypt_with_bad_header); tcase_add_test(tc_jwe, test_cjose_jwe_encrypt_with_bad_key); tcase_add_test(tc_jwe, test_cjose_jwe_encrypt_with_bad_content); tcase_add_test(tc_jwe, test_cjose_jwe_import_export_compare); tcase_add_test(tc_jwe, test_cjose_jwe_import_invalid_serialization); tcase_add_test(tc_jwe, test_cjose_jwe_decrypt_bad_params); tcase_add_test(tc_jwe, test_cjose_jwe_multiple_recipients); suite_add_tcase(suite, tc_jwe); return suite; }
1
C
CWE-327
Use of a Broken or Risky Cryptographic Algorithm
The product uses a broken or risky cryptographic algorithm or protocol.
https://cwe.mitre.org/data/definitions/327.html
safe
OE_INLINE void _handle_oret( oe_sgx_td_t* td, uint16_t func, uint16_t result, uint64_t arg) { oe_callsite_t* callsite = td->callsites; if (!callsite) return; td->oret_func = func; td->oret_result = result; td->oret_arg = arg; /* Restore the FXSTATE and flags */ asm volatile( "pushq %[rflags] \n\t" // Restore flags. "popfq \n\t" "fldcw %[fcw] \n\t" // Restore x87 control word "ldmxcsr %[mxcsr] \n\t" // Restore MXCSR "lfence \n\t" // MXCSR Configuration Dependent Timing (MCDT) mitigation : [mxcsr] "=m"(callsite->mxcsr), [fcw] "=m"(callsite->fcw), [rflags] "=m"(callsite->rflags) : : "cc"); oe_longjmp(&callsite->jmpbuf, 1); }
1
C
CWE-665
Improper Initialization
The product does not initialize or incorrectly initializes a resource, which might leave the resource in an unexpected state when it is accessed or used.
https://cwe.mitre.org/data/definitions/665.html
safe
void _reset_fxsave_state() { /* Initialize the FXSAVE state values to Linux x86-64 ABI defined values: * FCW = 0x037F, MXCSR = 0x1FBF, MXCSR mask = 0xFFFF */ static OE_ALIGNED(OE_FXSAVE_ALIGNMENT) const uint64_t _initial_fxstate[OE_FXSAVE_AREA_SIZE / sizeof(uint64_t)] = { 0x037F, 0, 0, 0xFFFF00001FBF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0x80000002, 0, 0, 0, 0, 0, 0, }; asm volatile("fxrstor %[fx_state] \n\t" : : [fx_state] "m"(_initial_fxstate) :); }
1
C
CWE-665
Improper Initialization
The product does not initialize or incorrectly initializes a resource, which might leave the resource in an unexpected state when it is accessed or used.
https://cwe.mitre.org/data/definitions/665.html
safe
JSON_read(int fd) { uint32_t hsize, nsize; size_t strsize; char *str; cJSON *json = NULL; int rc; /* * Read a four-byte integer, which is the length of the JSON to follow. * Then read the JSON into a buffer and parse it. Return a parsed JSON * structure, NULL if there was an error. */ if (Nread(fd, (char*) &nsize, sizeof(nsize), Ptcp) >= 0) { hsize = ntohl(nsize); /* Allocate a buffer to hold the JSON */ strsize = hsize + 1; /* +1 for trailing NULL */ if (strsize) { str = (char *) calloc(sizeof(char), strsize); if (str != NULL) { rc = Nread(fd, str, hsize, Ptcp); if (rc >= 0) { /* * We should be reading in the number of bytes corresponding to the * length in that 4-byte integer. If we don't the socket might have * prematurely closed. Only do the JSON parsing if we got the * correct number of bytes. */ if (rc == hsize) { json = cJSON_Parse(str); } else { printf("WARNING: Size of data read does not correspond to offered length\n"); } } } free(str); } else { printf("WARNING: Data length overflow\n"); } } return json; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static BOOL nsc_stream_initialize(NSC_CONTEXT* context, wStream* s) { WINPR_ASSERT(context); WINPR_ASSERT(context->priv); if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 20)) return FALSE; size_t total = 0; for (size_t i = 0; i < 4; i++) { Stream_Read_UINT32(s, context->PlaneByteCount[i]); total += context->PlaneByteCount[i]; } Stream_Read_UINT8(s, context->ColorLossLevel); /* ColorLossLevel (1 byte) */ Stream_Read_UINT8(s, context->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */ Stream_Seek(s, 2); /* Reserved (2 bytes) */ context->Planes = Stream_Pointer(s); context->PlanesSize = total; return Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, total); }
1
C
CWE-125
Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
https://cwe.mitre.org/data/definitions/125.html
safe
static BOOL nsc_rle_decompress_data(NSC_CONTEXT* context) { if (!context) return FALSE; const BYTE* rle = context->Planes; size_t rleSize = context->PlanesSize; WINPR_ASSERT(rle); for (size_t i = 0; i < 4; i++) { const UINT32 originalSize = context->OrgByteCount[i]; const UINT32 planeSize = context->PlaneByteCount[i]; if (rleSize < planeSize) return FALSE; if (planeSize == 0) { if (context->priv->PlaneBuffersLength < originalSize) return FALSE; FillMemory(context->priv->PlaneBuffers[i], originalSize, 0xFF); } else if (planeSize < originalSize) { if (!nsc_rle_decode(rle, rleSize, context->priv->PlaneBuffers[i], context->priv->PlaneBuffersLength, originalSize)) return FALSE; } else { if (context->priv->PlaneBuffersLength < originalSize) return FALSE; if (rleSize < originalSize) return FALSE; CopyMemory(context->priv->PlaneBuffers[i], rle, originalSize); } rle += planeSize; } return TRUE; }
1
C
CWE-125
Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
https://cwe.mitre.org/data/definitions/125.html
safe
static BOOL nsc_rle_decode(const BYTE* in, size_t inSize, BYTE* out, UINT32 outSize, UINT32 originalSize) { UINT32 left = originalSize; while (left > 4) { if (inSize < 1) return FALSE; inSize--; const BYTE value = *in++; UINT32 len = 0; if (left == 5) { if (outSize < 1) return FALSE; outSize--; *out++ = value; left--; } else if (inSize < 1) return FALSE; else if (value == *in) { inSize--; in++; if (inSize < 1) return FALSE; else if (*in < 0xFF) { inSize--; len = (UINT32)*in++; len += 2; } else { if (inSize < 5) return FALSE; inSize -= 5; in++; len = ((UINT32)(*in++)); len |= ((UINT32)(*in++)) << 8U; len |= ((UINT32)(*in++)) << 16U; len |= ((UINT32)(*in++)) << 24U; } if (outSize < len) return FALSE; outSize -= len; FillMemory(out, len, value); out += len; left -= len; } else { if (outSize < 1) return FALSE; outSize--; *out++ = value; left--; } } if ((outSize < 4) || (left < 4)) return FALSE; if (inSize < 4) return FALSE; memcpy(out, in, 4); return TRUE; }
1
C
CWE-125
Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
https://cwe.mitre.org/data/definitions/125.html
safe
static int ncrush_generate_tables(NCRUSH_CONTEXT* context) { UINT32 k, i; int j, l; k = 0; WINPR_ASSERT(context); WINPR_ASSERT(28 < ARRAYSIZE(LOMBitsLUT)); for (i = 0; i < 28; i++) { for (j = 0; j < 1 << LOMBitsLUT[i]; j++) { l = (k++) + 2; context->HuffTableLOM[l] = (int)i; } } for (k = 2; k < 4096; k++) { if ((k - 2) >= 768) i = 28; else i = context->HuffTableLOM[k]; if (i >= ARRAYSIZE(LOMBitsLUT)) return -1; if (i >= ARRAYSIZE(LOMBaseLUT)) return -1; if (((((1 << LOMBitsLUT[i]) - 1) & (k - 2)) + LOMBaseLUT[i]) != k) return -1; } k = 0; for (i = 0; i < 16; i++) { for (j = 0; j < 1 << CopyOffsetBitsLUT[i]; j++) { l = k++ + 2; context->HuffTableCopyOffset[l] = i; } } k /= 128; for (i = 16; i < 32; i++) { for (j = 0; j < 1 << (CopyOffsetBitsLUT[i] - 7); j++) { l = k++ + 2 + 256; context->HuffTableCopyOffset[l] = i; } } if ((k + 256) > 1024) return -1; return 1; }
1
C
CWE-120
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
https://cwe.mitre.org/data/definitions/120.html
safe
_blackbox_vlogger(int32_t target, struct qb_log_callsite *cs, struct timespec *timestamp, va_list ap) { size_t max_size; size_t actual_size; uint32_t fn_size; char *chunk; char *msg_len_pt; uint32_t msg_len; struct qb_log_target *t = qb_log_target_get(target); if (t->instance == NULL) { return; } fn_size = strlen(cs->function) + 1; actual_size = 4 * sizeof(uint32_t) + sizeof(uint8_t) + fn_size + sizeof(struct timespec); max_size = actual_size + t->max_line_length; chunk = qb_rb_chunk_alloc(t->instance, max_size); if (chunk == NULL) { /* something bad has happened. abort blackbox logging */ qb_util_perror(LOG_ERR, "Blackbox allocation error, aborting blackbox log %s", t->filename); qb_rb_close(qb_rb_lastref_and_ret( (struct qb_ringbuffer_s **) &t->instance )); return; } /* line number */ memcpy(chunk, &cs->lineno, sizeof(uint32_t)); chunk += sizeof(uint32_t); /* tags */ memcpy(chunk, &cs->tags, sizeof(uint32_t)); chunk += sizeof(uint32_t); /* log level/priority */ memcpy(chunk, &cs->priority, sizeof(uint8_t)); chunk += sizeof(uint8_t); /* function name */ memcpy(chunk, &fn_size, sizeof(uint32_t)); chunk += sizeof(uint32_t); memcpy(chunk, cs->function, fn_size); chunk += fn_size; /* timestamp */ memcpy(chunk, timestamp, sizeof(struct timespec)); chunk += sizeof(struct timespec); /* log message length */ msg_len_pt = chunk; chunk += sizeof(uint32_t); /* log message */ msg_len = qb_vsnprintf_serialize(chunk, t->max_line_length, cs->format, ap); if (msg_len >= t->max_line_length) { chunk = msg_len_pt + sizeof(uint32_t); /* Reset */ /* Leave this at QB_LOG_MAX_LEN so as not to overflow the blackbox */ msg_len = qb_vsnprintf_serialize(chunk, QB_LOG_MAX_LEN, "Log message too long to be stored in the blackbox. "\ "Maximum is QB_LOG_MAX_LEN" , ap); } actual_size += msg_len; /* now that we know the length, write it */ memcpy(msg_len_pt, &msg_len, sizeof(uint32_t)); (void)qb_rb_chunk_commit(t->instance, actual_size); }
1
C
CWE-120
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
https://cwe.mitre.org/data/definitions/120.html
safe
START_TEST(test_log_long_msg) { int lpc; int rc; int i, max = 1000; char *buffer = calloc(1, max); qb_log_init("test", LOG_USER, LOG_DEBUG); rc = qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE); ck_assert_int_eq(rc, 0); rc = qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, 1024); ck_assert_int_eq(rc, 0); rc = qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE); ck_assert_int_eq(rc, 0); rc = qb_log_filter_ctl(QB_LOG_BLACKBOX, QB_LOG_FILTER_ADD, QB_LOG_FILTER_FILE, "*", LOG_TRACE); ck_assert_int_eq(rc, 0); for (lpc = 500; lpc < max; lpc++) { lpc++; for(i = 0; i < max; i++) { buffer[i] = 'a' + (i % 10); } buffer[lpc%600] = 0; qb_log(LOG_INFO, "Message %d %d - %s", lpc, lpc%600, buffer); } rc = qb_log_blackbox_write_to_file("blackbox.dump"); ck_assert_int_gt(rc, 0); rc = qb_log_blackbox_print_from_file("blackbox.dump"); ck_assert_int_le(rc, 0); unlink("blackbox.dump"); qb_log_fini(); }
1
C
CWE-120
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
https://cwe.mitre.org/data/definitions/120.html
safe
consume_count(type) const char **type; { // Note by RizinOrg: // to prevent the overflow check to be optimized out // by the compiler, this variable needs to be volatile. volatile int count = 0; if (!isdigit((unsigned char)**type)) return -1; while (isdigit((unsigned char)**type)) { count *= 10; /* Check for overflow. We assume that count is represented using two's-complement; no power of two is divisible by ten, so if an overflow occurs when multiplying by ten, the result will not be a multiple of ten. */ if ((count % 10) != 0) { while (isdigit((unsigned char)**type)) (*type)++; return -1; } count += **type - '0'; (*type)++; } return (count); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int h1_parse_cont_len_header(struct h1m *h1m, struct ist *value) { char *e, *n; long long cl; int not_first = !!(h1m->flags & H1_MF_CLEN); struct ist word; word.ptr = value->ptr; e = value->ptr + value->len; while (1) { if (word.ptr >= e) { /* empty header or empty value */ goto fail; } /* skip leading delimiter and blanks */ if (unlikely(HTTP_IS_LWS(*word.ptr))) { word.ptr++; continue; } /* digits only now */ for (cl = 0, n = word.ptr; n < e; n++) { unsigned int c = *n - '0'; if (unlikely(c > 9)) { /* non-digit */ if (unlikely(n == word.ptr)) // spaces only goto fail; break; } if (unlikely(cl > ULLONG_MAX / 10ULL)) goto fail; /* multiply overflow */ cl = cl * 10ULL; if (unlikely(cl + c < cl)) goto fail; /* addition overflow */ cl = cl + c; } /* keep a copy of the exact cleaned value */ word.len = n - word.ptr; /* skip trailing LWS till next comma or EOL */ for (; n < e; n++) { if (!HTTP_IS_LWS(*n)) { if (unlikely(*n != ',')) goto fail; break; } } /* if duplicate, must be equal */ if (h1m->flags & H1_MF_CLEN && cl != h1m->body_len) goto fail; /* OK, store this result as the one to be indexed */ h1m->flags |= H1_MF_CLEN; h1m->curr_len = h1m->body_len = cl; *value = word; /* Now either n==e and we're done, or n points to the comma, * and we skip it and continue. */ if (n++ == e) break; word.ptr = n; } /* here we've reached the end with a single value or a series of * identical values, all matching previous series if any. The last * parsed value was sent back into <value>. We just have to decide * if this occurrence has to be indexed (it's the first one) or * silently skipped (it's not the first one) */ return !not_first; fail: return -1; }
1
C
CWE-444
Inconsistent Interpretation of HTTP Requests ('HTTP Request/Response Smuggling')
The product acts as an intermediary HTTP agent (such as a proxy or firewall) in the data flow between two entities such as a client and server, but it does not interpret malformed HTTP requests or responses in ways that are consistent with how the messages will be processed by those entities that are at the ultimate destination.
https://cwe.mitre.org/data/definitions/444.html
safe
void client_reset(t_client *client) { char *hash; char *msg; char *cidinfo; debug(LOG_DEBUG, "Resetting client [%s]", client->mac); // Reset traffic counters client->counters.incoming = 0; client->counters.outgoing = 0; client->counters.last_updated = time(NULL); // Reset session time client->session_start = 0; client->session_end = 0; // Reset token and hid hash = safe_calloc(STATUS_BUF); client->token = safe_calloc(STATUS_BUF); safe_snprintf(client->token, STATUS_BUF, "%04hx%04hx", rand16(), rand16()); hash_str(hash, STATUS_BUF, client->token); client->hid = safe_strdup(hash); free(hash); // Reset custom, client_type and cpi_query client->custom = safe_calloc(MID_BUF); client->client_type = safe_calloc(STATUS_BUF); if (!client->cpi_query) { client->cpi_query = safe_calloc(STATUS_BUF); } //Reset cid and remove cidfile using rmcid if (client->cid) { if (strlen(client->cid) > 0) { msg = safe_calloc(SMALL_BUF); cidinfo = safe_calloc(MID_BUF); safe_snprintf(cidinfo, MID_BUF, "cid=\"%s\"", client->cid); write_client_info(msg, SMALL_BUF, "rmcid", client->cid, cidinfo); free(msg); free(cidinfo); } } client->cid = safe_calloc(SMALL_BUF); }
1
C
CWE-401
Missing Release of Memory after Effective Lifetime
The product does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory.
https://cwe.mitre.org/data/definitions/401.html
safe
_client_list_free_node(t_client *client) { char *msg; char *cidinfo; if (client->cid) { // Remove any existing cidfile: if (strlen(client->cid) > 0) { msg = safe_calloc(SMALL_BUF); cidinfo = safe_calloc(MID_BUF); safe_snprintf(cidinfo, MID_BUF, "cid=\"%s\"", client->cid); write_client_info(msg, SMALL_BUF, "rmcid", client->cid, cidinfo); free(msg); free(cidinfo); } } free(client->token); free(client->hid); free(client->custom); free(client->client_type); free(client->cid); if (strcmp(client->cpi_query, "") == 0) { free(client->cpi_query); } free(client); }
1
C
CWE-401
Missing Release of Memory after Effective Lifetime
The product does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory.
https://cwe.mitre.org/data/definitions/401.html
safe
void crypto_bignum_free(struct bignum **a) { if (a && *a) panic(); }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_allocate_keypair(struct dh_keypair *key, size_t size_bits) { DH_TRACE("Allocate Keypair of %zu bits", size_bits); /* Initialize the key fields to NULL */ memset(key, 0, sizeof(*key)); /* Allocate Generator Scalar */ key->g = crypto_bignum_allocate(size_bits); if (!key->g) goto err; /* Allocate Prime Number Modulus */ key->p = crypto_bignum_allocate(size_bits); if (!key->p) goto err; /* Allocate Private key X */ key->x = crypto_bignum_allocate(size_bits); if (!key->x) goto err; /* Allocate Public Key Y */ key->y = crypto_bignum_allocate(size_bits); if (!key->y) goto err; /* Allocate Subprime even if not used */ key->q = crypto_bignum_allocate(size_bits); if (!key->q) goto err; return TEE_SUCCESS; err: DH_TRACE("Allocation error"); crypto_bignum_free(&key->g); crypto_bignum_free(&key->p); crypto_bignum_free(&key->x); crypto_bignum_free(&key->y); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_allocate_publickey(struct dsa_public_key *key, size_t l_bits, size_t n_bits) { DSA_TRACE("DSA Allocate Public of L=%zu bits and N=%zu bits", l_bits, n_bits); /* Initialize the key fields to NULL */ memset(key, 0, sizeof(*key)); /* Allocate Generator Scalar */ key->g = crypto_bignum_allocate(l_bits); if (!key->g) goto err; /* Allocate Prime Number Modulus */ key->p = crypto_bignum_allocate(l_bits); if (!key->p) goto err; /* Allocate Prime Number Modulus */ key->q = crypto_bignum_allocate(n_bits); if (!key->q) goto err; /* Allocate Public Key Y */ key->y = crypto_bignum_allocate(l_bits); if (!key->y) goto err; return TEE_SUCCESS; err: DSA_TRACE("Allocation error"); crypto_bignum_free(&key->g); crypto_bignum_free(&key->p); crypto_bignum_free(&key->q); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_allocate_keypair(struct dsa_keypair *key, size_t l_bits, size_t n_bits) { DSA_TRACE("DSA allocate Keypair of L=%zu bits and N=%zu bits", l_bits, n_bits); /* Initialize the key fields to NULL */ memset(key, 0, sizeof(*key)); /* Allocate Generator Scalar */ key->g = crypto_bignum_allocate(l_bits); if (!key->g) goto err; /* Allocate Prime Number Modulus */ key->p = crypto_bignum_allocate(l_bits); if (!key->p) goto err; /* Allocate Prime Number Modulus */ key->q = crypto_bignum_allocate(n_bits); if (!key->q) goto err; /* Allocate Private key X */ key->x = crypto_bignum_allocate(n_bits); if (!key->x) goto err; /* Allocate Public Key Y */ key->y = crypto_bignum_allocate(l_bits); if (!key->y) goto err; return TEE_SUCCESS; err: DSA_TRACE("Allocation error"); crypto_bignum_free(&key->g); crypto_bignum_free(&key->p); crypto_bignum_free(&key->q); crypto_bignum_free(&key->x); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_allocate_publickey(struct ecc_public_key *key, uint32_t type __unused, size_t size_bits) { ECC_TRACE("Allocate Public Key of %zu bits", size_bits); /* Initialize the key fields to NULL */ memset(key, 0, sizeof(*key)); /* Allocate Public coordinate X */ key->x = crypto_bignum_allocate(size_bits); if (!key->x) goto err; /* Allocate Public coordinate Y */ key->y = crypto_bignum_allocate(size_bits); if (!key->y) goto err; return TEE_SUCCESS; err: ECC_TRACE("Allocation error"); crypto_bignum_free(&key->x); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static void do_free_publickey(struct ecc_public_key *key) { crypto_bignum_free(&key->x); crypto_bignum_free(&key->y); }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_allocate_keypair(struct ecc_keypair *key, uint32_t type __unused, size_t size_bits) { ECC_TRACE("Allocate Keypair of %zu bits", size_bits); /* Initialize the key fields to NULL */ memset(key, 0, sizeof(*key)); /* Allocate Secure Scalar */ key->d = crypto_bignum_allocate(size_bits); if (!key->d) goto err; /* Allocate Public coordinate X */ key->x = crypto_bignum_allocate(size_bits); if (!key->x) goto err; /* Allocate Public coordinate Y */ key->y = crypto_bignum_allocate(size_bits); if (!key->y) goto err; return TEE_SUCCESS; err: ECC_TRACE("Allocation error"); crypto_bignum_free(&key->d); crypto_bignum_free(&key->x); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static void do_free_keypair(struct rsa_keypair *key) { crypto_bignum_free(&key->e); crypto_bignum_free(&key->d); crypto_bignum_free(&key->n); crypto_bignum_free(&key->p); crypto_bignum_free(&key->q); crypto_bignum_free(&key->qp); crypto_bignum_free(&key->dp); crypto_bignum_free(&key->dq); }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static void do_free_publickey(struct rsa_public_key *key) { crypto_bignum_free(&key->e); crypto_bignum_free(&key->n); }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_allocate_publickey(struct rsa_public_key *key, size_t size_bits) { RSA_TRACE("Allocate Public Key of %zu bits", size_bits); /* Initialize all input key fields to 0 */ memset(key, 0, sizeof(*key)); /* Allocate the Public Exponent to maximum size */ key->e = crypto_bignum_allocate(MAX_BITS_EXP_E); if (!key->e) goto err_alloc_publickey; /* Allocate the Modulus (size_bits) [n = p * q] */ key->n = crypto_bignum_allocate(size_bits); if (!key->n) goto err_alloc_publickey; return TEE_SUCCESS; err_alloc_publickey: RSA_TRACE("Allocation error"); crypto_bignum_free(&key->e); crypto_bignum_free(&key->n); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static void do_free_publickey(struct ecc_public_key *s) { if (!s) return; crypto_bignum_free(&s->x); crypto_bignum_free(&s->y); }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_alloc_publickey(struct ecc_public_key *s, uint32_t type, size_t size_bits __unused) { /* This driver only supports ECDH/ECDSA */ if (type != TEE_TYPE_ECDSA_PUBLIC_KEY && type != TEE_TYPE_ECDH_PUBLIC_KEY) return TEE_ERROR_NOT_IMPLEMENTED; memset(s, 0, sizeof(*s)); if (!bn_alloc_max(&s->x)) goto err; if (!bn_alloc_max(&s->y)) goto err; return TEE_SUCCESS; err: crypto_bignum_free(&s->x); crypto_bignum_free(&s->y); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_alloc_keypair(struct ecc_keypair *s, uint32_t type, size_t size_bits __unused) { /* This driver only supports ECDH/ECDSA */ if (type != TEE_TYPE_ECDSA_KEYPAIR && type != TEE_TYPE_ECDH_KEYPAIR) return TEE_ERROR_NOT_IMPLEMENTED; memset(s, 0, sizeof(*s)); if (!bn_alloc_max(&s->d)) goto err; if (!bn_alloc_max(&s->x)) goto err; if (!bn_alloc_max(&s->y)) goto err; return TEE_SUCCESS; err: crypto_bignum_free(&s->d); crypto_bignum_free(&s->x); crypto_bignum_free(&s->y); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_alloc_keypair(struct rsa_keypair *s, size_t key_size_bits __unused) { memset(s, 0, sizeof(*s)); if (!bn_alloc_max(&s->e)) return TEE_ERROR_OUT_OF_MEMORY; if (!bn_alloc_max(&s->d)) goto err; if (!bn_alloc_max(&s->n)) goto err; if (!bn_alloc_max(&s->p)) goto err; if (!bn_alloc_max(&s->q)) goto err; if (!bn_alloc_max(&s->qp)) goto err; if (!bn_alloc_max(&s->dp)) goto err; if (!bn_alloc_max(&s->dq)) goto err; return TEE_SUCCESS; err: crypto_bignum_free(&s->e); crypto_bignum_free(&s->d); crypto_bignum_free(&s->n); crypto_bignum_free(&s->p); crypto_bignum_free(&s->q); crypto_bignum_free(&s->qp); crypto_bignum_free(&s->dp); crypto_bignum_free(&s->dq); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static void do_free_publickey(struct rsa_public_key *s) { if (s) { crypto_bignum_free(&s->n); crypto_bignum_free(&s->e); } }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static void do_free_keypair(struct rsa_keypair *s) { sss_status_t st = kStatus_SSS_Fail; sss_se05x_object_t k_object = { }; uint32_t key_id = 0; if (!s) return; key_id = se050_rsa_keypair_from_nvm(s); if (key_id) { st = sss_se05x_key_object_get_handle(&k_object, key_id); if (st == kStatus_SSS_Success) sss_se05x_key_store_erase_key(se050_kstore, &k_object); } crypto_bignum_free(&s->e); crypto_bignum_free(&s->d); crypto_bignum_free(&s->n); crypto_bignum_free(&s->p); crypto_bignum_free(&s->q); crypto_bignum_free(&s->qp); crypto_bignum_free(&s->dp); crypto_bignum_free(&s->dq); }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
static TEE_Result do_alloc_publickey(struct rsa_public_key *s, size_t key_size_bits __unused) { memset(s, 0, sizeof(*s)); if (!bn_alloc_max(&s->e)) return TEE_ERROR_OUT_OF_MEMORY; if (!bn_alloc_max(&s->n)) { crypto_bignum_free(&s->e); return TEE_ERROR_OUT_OF_MEMORY; } return TEE_SUCCESS; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
TEE_Result crypto_acipher_alloc_dh_keypair(struct dh_keypair *s, size_t key_size_bits __unused) { memset(s, 0, sizeof(*s)); if (!bn_alloc_max(&s->g)) return TEE_ERROR_OUT_OF_MEMORY; if (!bn_alloc_max(&s->p)) goto err; if (!bn_alloc_max(&s->y)) goto err; if (!bn_alloc_max(&s->x)) goto err; if (!bn_alloc_max(&s->q)) goto err; return TEE_SUCCESS; err: crypto_bignum_free(&s->g); crypto_bignum_free(&s->p); crypto_bignum_free(&s->y); crypto_bignum_free(&s->x); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
TEE_Result crypto_acipher_alloc_dsa_public_key(struct dsa_public_key *s, size_t key_size_bits __unused) { memset(s, 0, sizeof(*s)); if (!bn_alloc_max(&s->g)) return TEE_ERROR_OUT_OF_MEMORY; if (!bn_alloc_max(&s->p)) goto err; if (!bn_alloc_max(&s->q)) goto err; if (!bn_alloc_max(&s->y)) goto err; return TEE_SUCCESS; err: crypto_bignum_free(&s->g); crypto_bignum_free(&s->p); crypto_bignum_free(&s->q); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
TEE_Result crypto_acipher_alloc_dsa_keypair(struct dsa_keypair *s, size_t key_size_bits __unused) { memset(s, 0, sizeof(*s)); if (!bn_alloc_max(&s->g)) return TEE_ERROR_OUT_OF_MEMORY; if (!bn_alloc_max(&s->p)) goto err; if (!bn_alloc_max(&s->q)) goto err; if (!bn_alloc_max(&s->y)) goto err; if (!bn_alloc_max(&s->x)) goto err; return TEE_SUCCESS; err: crypto_bignum_free(&s->g); crypto_bignum_free(&s->p); crypto_bignum_free(&s->q); crypto_bignum_free(&s->y); return TEE_ERROR_OUT_OF_MEMORY; }
1
C
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
msg_puts_printf(char_u *str, int maxlen) { char_u *s = str; char_u *buf = NULL; char_u *p = s; #ifdef MSWIN if (!(silent_mode && p_verbose == 0)) mch_settmode(TMODE_COOK); // handle CR and NL correctly #endif while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) { if (!(silent_mode && p_verbose == 0)) { // NL --> CR NL translation (for Unix, not for "--version") if (*s == NL) { int n = (int)(s - p); buf = alloc(n + 3); if (buf != NULL) { memcpy(buf, p, n); if (!info_message) buf[n++] = CAR; buf[n++] = NL; buf[n++] = NUL; if (info_message) // informative message, not an error mch_msg((char *)buf); else mch_errmsg((char *)buf); vim_free(buf); } p = s + 1; } } // primitive way to compute the current column #ifdef FEAT_RIGHTLEFT if (cmdmsg_rl) { if (*s == CAR || *s == NL) msg_col = Columns - 1; else --msg_col; } else #endif { if (*s == CAR || *s == NL) msg_col = 0; else ++msg_col; } ++s; } if (*p != NUL && !(silent_mode && p_verbose == 0)) { char_u *tofree = NULL; if (maxlen > 0 && STRLEN(p) > (size_t)maxlen) { tofree = vim_strnsave(p, (size_t)maxlen); p = tofree; } if (p != NULL) { if (info_message) mch_msg((char *)p); else mch_errmsg((char *)p); vim_free(tofree); } } msg_didout = TRUE; // assume that line is not empty #ifdef MSWIN if (!(silent_mode && p_verbose == 0)) mch_settmode(TMODE_RAW); #endif }
0
C
CWE-122
Heap-based Buffer Overflow
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
https://cwe.mitre.org/data/definitions/122.html
vulnerable