Skip to content

Commit 23e96b8

Browse files
committed
other fixes
1 parent 843b280 commit 23e96b8

File tree

7 files changed

+34
-30
lines changed

7 files changed

+34
-30
lines changed

crypto/bio/bio.c

+25-22
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,15 @@ static int call_bio_callback_with_processed(BIO *bio, const int oper,
8585
// Pass the original BIO's return value to the callback. If the callback
8686
// is successful return processed from the callback, if the callback is
8787
// not successful return the callback's return value.
88-
ret = (int)bio->callback_ex(bio, oper, buf, len, 0, 0L, ret, &processed);
89-
if (ret > 0) {
90-
// BIO will only read int |len| bytes so this is a safe cast
91-
ret = (int)processed;
88+
long callback_ret = bio->callback_ex(bio, oper, buf, len, 0, 0L, ret, &processed);
89+
if (callback_ret <= INT_MAX) {
90+
ret = (int)callback_ret;
91+
if (ret > 0) {
92+
// BIO will only read int |len| bytes so this is a safe cast
93+
ret = (int)processed;
94+
}
9295
}
96+
9397
}
9498
return ret;
9599
}
@@ -131,9 +135,9 @@ int BIO_free(BIO *bio) {
131135
bio->method->destroy(bio);
132136
}
133137
if (HAS_CALLBACK(bio)) {
134-
int ret = (int)bio->callback_ex(bio, BIO_CB_FREE, NULL, 0, 0, 0L, 1L, NULL);
135-
if (ret <= 0) {
136-
return ret;
138+
long ret = bio->callback_ex(bio, BIO_CB_FREE, NULL, 0, 0, 0L, 1L, NULL);
139+
if (ret <= 0 && ret >= INT_MIN) {
140+
return (int)ret;
137141
}
138142
}
139143

@@ -167,9 +171,9 @@ int BIO_read(BIO *bio, void *buf, int len) {
167171
}
168172

169173
if (HAS_CALLBACK(bio)) {
170-
ret = (int)bio->callback_ex(bio, BIO_CB_READ, buf, len, 0, 0L, 1L, NULL);
171-
if (ret <= 0) {
172-
return ret;
174+
long callback_ret = bio->callback_ex(bio, BIO_CB_READ, buf, len, 0, 0L, 1L, NULL);
175+
if (callback_ret <= 0 && callback_ret >= INT_MIN) {
176+
return (int)callback_ret;
173177
}
174178
}
175179
if (!bio->init) {
@@ -217,18 +221,17 @@ int BIO_gets(BIO *bio, char *buf, int len) {
217221
return 0;
218222
}
219223

220-
int ret = 0;
221224
if (HAS_CALLBACK(bio)) {
222-
ret = (int)bio->callback_ex(bio, BIO_CB_GETS, buf, len, 0, 0L, 1L, NULL);
223-
if (ret <= 0) {
224-
return ret;
225+
long callback_ret = bio->callback_ex(bio, BIO_CB_GETS, buf, len, 0, 0L, 1L, NULL);
226+
if (callback_ret <= 0 && callback_ret >= INT_MIN) {
227+
return (int)callback_ret;
225228
}
226229
}
227230
if (!bio->init) {
228231
OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED);
229232
return -2;
230233
}
231-
ret = bio->method->bgets(bio, buf, len);
234+
int ret = bio->method->bgets(bio, buf, len);
232235
if (ret > 0) {
233236
bio->num_read += ret;
234237
}
@@ -248,9 +251,9 @@ int BIO_write(BIO *bio, const void *in, int inl) {
248251
}
249252

250253
if (HAS_CALLBACK(bio)) {
251-
ret = (int)bio->callback_ex(bio, BIO_CB_WRITE, in, inl, 0, 0L, 1L, NULL);
252-
if (ret <= 0) {
253-
return ret;
254+
long callback_ret = bio->callback_ex(bio, BIO_CB_WRITE, in, inl, 0, 0L, 1L, NULL);
255+
if (callback_ret <= 0 && callback_ret >= INT_MIN) {
256+
return (int)callback_ret;
254257
}
255258
}
256259

@@ -317,18 +320,18 @@ int BIO_puts(BIO *bio, const char *in) {
317320
OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD);
318321
return -2;
319322
}
320-
int ret = 0;
321323
if(HAS_CALLBACK(bio)) {
322-
ret = (int)bio->callback_ex(bio, BIO_CB_PUTS, in, 0, 0, 0L, 1L, NULL);
323-
if (ret <= 0) {
324-
return ret;
324+
long callback_ret = bio->callback_ex(bio, BIO_CB_PUTS, in, 0, 0, 0L, 1L, NULL);
325+
if (callback_ret <= 0 && callback_ret >= INT_MIN) {
326+
return (int)callback_ret;
325327
}
326328
}
327329

328330
if (!bio->init) {
329331
OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED);
330332
return -2;
331333
}
334+
int ret = 0;
332335
if (bio->method->bputs != NULL) {
333336
ret = bio->method->bputs(bio, in);
334337
} else {

crypto/bio/hexdump.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ static int hexdump_write(struct hexdump_ctx *ctx, const uint8_t *data,
9898
for (size_t i = 0; i < len; i++) {
9999
if (ctx->used == 0) {
100100
// The beginning of a line.
101-
BIO_indent(ctx->bio, ctx->indent, UINT_MAX);
101+
if (!BIO_indent(ctx->bio, ctx->indent, UINT_MAX)) {
102+
return 0;
103+
}
102104

103105
hexbyte(&buf[0], ctx->n >> 24);
104106
hexbyte(&buf[2], ctx->n >> 16);

crypto/bn_extra/convert.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ BIGNUM *BN_mpi2bn(const uint8_t *in, size_t len, BIGNUM *out) {
448448
}
449449
out->neg = ((*in) & 0x80) != 0;
450450
if (out->neg) {
451-
BN_clear_bit(out, BN_num_bits(out) - 1);
451+
BN_clear_bit(out, (int)BN_num_bits(out) - 1);
452452
}
453453
return out;
454454
}

crypto/evp_extra/evp_test.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ static bool TestEVP(FileTest *t, KeyMap *key_map) {
584584
return false;
585585
}
586586
actual.resize(len);
587-
VerifyEVPSignOut(key_name, input, actual, output, ctx.get(), len);
587+
VerifyEVPSignOut(key_name, std::move(input), std::move(actual),
588+
std::move(output), ctx.get(), len);
588589
return true;
589590
}
590591

crypto/fipsmodule/modes/cbc.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ void CRYPTO_cbc128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
8585
}
8686
(*block)(out, out, key);
8787
iv = out;
88+
// This will always be true as a result of the first while loop
8889
if (len <= 16) {
8990
break;
9091
}
91-
len -= 16;
92-
in += 16;
93-
out += 16;
9492
}
9593

9694
OPENSSL_memcpy(ivec, iv, 16);

crypto/pkcs7/bio/bio_md_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ TEST_P(BIOMessageDigestTest, Randomized) {
183183
};
184184
std::vector<size_t> v(1000);
185185
std::generate(v.begin(), v.end(), [] { return rand() % MESSAGE_LEN; });
186-
io_patterns.push_back(v);
186+
io_patterns.push_back(std::move(v));
187187

188188
for (auto io_pattern : io_patterns) {
189189
message.clear();

ssl/test/test_config.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ static std::vector<std::string> DecodeHexStrings(
10811081
return ret;
10821082
}
10831083

1084-
ret.push_back(binary);
1084+
ret.push_back(std::move(binary));
10851085
}
10861086

10871087
return ret;

0 commit comments

Comments
 (0)