Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCRUTINICE fixes #2103

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions crypto/bio/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ static int call_bio_callback_with_processed(BIO *bio, const int oper,
// Pass the original BIO's return value to the callback. If the callback
// is successful return processed from the callback, if the callback is
// not successful return the callback's return value.
ret = (int)bio->callback_ex(bio, oper, buf, len, 0, 0L, ret, &processed);
if (ret > 0) {
// BIO will only read int |len| bytes so this is a safe cast
ret = (int)processed;
long callback_ret = bio->callback_ex(bio, oper, buf, len, 0, 0L, ret, &processed);
if (callback_ret <= INT_MAX && callback_ret >= INT_MIN) {
ret = (int)callback_ret;
if (ret > 0) {
// BIO will only read int |len| bytes so this is a safe cast
ret = (int)processed;
}
} else {
ret = -1;
}
}
return ret;
Expand Down Expand Up @@ -131,9 +136,12 @@ int BIO_free(BIO *bio) {
bio->method->destroy(bio);
}
if (HAS_CALLBACK(bio)) {
int ret = (int)bio->callback_ex(bio, BIO_CB_FREE, NULL, 0, 0, 0L, 1L, NULL);
long ret = bio->callback_ex(bio, BIO_CB_FREE, NULL, 0, 0, 0L, 1L, NULL);
if (ret <= 0) {
return ret;
if (ret >= INT_MIN) {
return (int)ret;
}
return INT_MIN;
}
}

Expand Down Expand Up @@ -167,9 +175,12 @@ int BIO_read(BIO *bio, void *buf, int len) {
}

if (HAS_CALLBACK(bio)) {
ret = (int)bio->callback_ex(bio, BIO_CB_READ, buf, len, 0, 0L, 1L, NULL);
if (ret <= 0) {
return ret;
long callback_ret = bio->callback_ex(bio, BIO_CB_READ, buf, len, 0, 0L, 1L, NULL);
if (callback_ret <= 0) {
if (callback_ret >= INT_MIN) {
return (int)callback_ret;
}
return INT_MIN;
}
}
if (!bio->init) {
Expand Down Expand Up @@ -217,18 +228,20 @@ int BIO_gets(BIO *bio, char *buf, int len) {
return 0;
}

int ret = 0;
if (HAS_CALLBACK(bio)) {
ret = (int)bio->callback_ex(bio, BIO_CB_GETS, buf, len, 0, 0L, 1L, NULL);
if (ret <= 0) {
return ret;
long callback_ret = bio->callback_ex(bio, BIO_CB_GETS, buf, len, 0, 0L, 1L, NULL);
if (callback_ret <= 0) {
if (callback_ret >= INT_MIN) {
return (int)callback_ret;
}
return INT_MIN;
}
}
if (!bio->init) {
OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED);
return -2;
}
ret = bio->method->bgets(bio, buf, len);
int ret = bio->method->bgets(bio, buf, len);
if (ret > 0) {
bio->num_read += ret;
}
Expand All @@ -248,9 +261,12 @@ int BIO_write(BIO *bio, const void *in, int inl) {
}

if (HAS_CALLBACK(bio)) {
ret = (int)bio->callback_ex(bio, BIO_CB_WRITE, in, inl, 0, 0L, 1L, NULL);
if (ret <= 0) {
return ret;
long callback_ret = bio->callback_ex(bio, BIO_CB_WRITE, in, inl, 0, 0L, 1L, NULL);
if (callback_ret <= 0) {
if (callback_ret >= INT_MIN) {
return (int)callback_ret;
}
return INT_MIN;
}
}

Expand Down Expand Up @@ -317,18 +333,21 @@ int BIO_puts(BIO *bio, const char *in) {
OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD);
return -2;
}
int ret = 0;
if(HAS_CALLBACK(bio)) {
ret = (int)bio->callback_ex(bio, BIO_CB_PUTS, in, 0, 0, 0L, 1L, NULL);
if (ret <= 0) {
return ret;
long callback_ret = bio->callback_ex(bio, BIO_CB_PUTS, in, 0, 0, 0L, 1L, NULL);
if (callback_ret <= 0) {
if (callback_ret >= INT_MIN) {
return (int)callback_ret;
}
return INT_MIN;
}
}

if (!bio->init) {
OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED);
return -2;
}
int ret = 0;
if (bio->method->bputs != NULL) {
ret = bio->method->bputs(bio, in);
} else {
Expand Down
4 changes: 3 additions & 1 deletion crypto/bio/hexdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ static int hexdump_write(struct hexdump_ctx *ctx, const uint8_t *data,
for (size_t i = 0; i < len; i++) {
if (ctx->used == 0) {
// The beginning of a line.
BIO_indent(ctx->bio, ctx->indent, UINT_MAX);
if (!BIO_indent(ctx->bio, ctx->indent, UINT_MAX)) {
return 0;
}

hexbyte(&buf[0], ctx->n >> 24);
hexbyte(&buf[2], ctx->n >> 16);
Expand Down
9 changes: 8 additions & 1 deletion crypto/bn_extra/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,14 @@ BIGNUM *BN_mpi2bn(const uint8_t *in, size_t len, BIGNUM *out) {
}
out->neg = ((*in) & 0x80) != 0;
if (out->neg) {
BN_clear_bit(out, BN_num_bits(out) - 1);
unsigned num_bits = BN_num_bits(out);
if (num_bits >= INT_MAX) {
if (out_is_alloced) {
BN_free(out);
}
return NULL;
}
BN_clear_bit(out, (int)num_bits - 1);
}
return out;
}
Expand Down
3 changes: 2 additions & 1 deletion crypto/evp_extra/evp_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ static bool TestEVP(FileTest *t, KeyMap *key_map) {
return false;
}
actual.resize(len);
VerifyEVPSignOut(key_name, input, actual, output, ctx.get(), len);
VerifyEVPSignOut(key_name, std::move(input), std::move(actual),
std::move(output), ctx.get(), len);
return true;
}

Expand Down
8 changes: 1 addition & 7 deletions crypto/fipsmodule/modes/cbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void CRYPTO_cbc128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
out += 16;
}

while (len) {
if (len > 0) {
for (n = 0; n < 16 && n < len; ++n) {
out[n] = in[n] ^ iv[n];
}
Expand All @@ -85,12 +85,6 @@ void CRYPTO_cbc128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
}
(*block)(out, out, key);
iv = out;
if (len <= 16) {
break;
}
len -= 16;
in += 16;
out += 16;
}

OPENSSL_memcpy(ivec, iv, 16);
Expand Down
2 changes: 1 addition & 1 deletion crypto/pkcs7/bio/bio_md_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ TEST_P(BIOMessageDigestTest, Randomized) {
};
std::vector<size_t> v(1000);
std::generate(v.begin(), v.end(), [] { return rand() % MESSAGE_LEN; });
io_patterns.push_back(v);
io_patterns.push_back(std::move(v));

for (auto io_pattern : io_patterns) {
message.clear();
Expand Down
2 changes: 1 addition & 1 deletion ssl/test/test_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ static std::vector<std::string> DecodeHexStrings(
return ret;
}

ret.push_back(binary);
ret.push_back(std::move(binary));
}

return ret;
Expand Down
Loading