@@ -85,11 +85,15 @@ static int call_bio_callback_with_processed(BIO *bio, const int oper,
85
85
// Pass the original BIO's return value to the callback. If the callback
86
86
// is successful return processed from the callback, if the callback is
87
87
// 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
+ }
92
95
}
96
+
93
97
}
94
98
return ret ;
95
99
}
@@ -131,9 +135,9 @@ int BIO_free(BIO *bio) {
131
135
bio -> method -> destroy (bio );
132
136
}
133
137
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 ;
137
141
}
138
142
}
139
143
@@ -167,9 +171,9 @@ int BIO_read(BIO *bio, void *buf, int len) {
167
171
}
168
172
169
173
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 ;
173
177
}
174
178
}
175
179
if (!bio -> init ) {
@@ -217,18 +221,17 @@ int BIO_gets(BIO *bio, char *buf, int len) {
217
221
return 0 ;
218
222
}
219
223
220
- int ret = 0 ;
221
224
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 ;
225
228
}
226
229
}
227
230
if (!bio -> init ) {
228
231
OPENSSL_PUT_ERROR (BIO , BIO_R_UNINITIALIZED );
229
232
return -2 ;
230
233
}
231
- ret = bio -> method -> bgets (bio , buf , len );
234
+ int ret = bio -> method -> bgets (bio , buf , len );
232
235
if (ret > 0 ) {
233
236
bio -> num_read += ret ;
234
237
}
@@ -248,9 +251,9 @@ int BIO_write(BIO *bio, const void *in, int inl) {
248
251
}
249
252
250
253
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 ;
254
257
}
255
258
}
256
259
@@ -317,18 +320,18 @@ int BIO_puts(BIO *bio, const char *in) {
317
320
OPENSSL_PUT_ERROR (BIO , BIO_R_UNSUPPORTED_METHOD );
318
321
return -2 ;
319
322
}
320
- int ret = 0 ;
321
323
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 ;
325
327
}
326
328
}
327
329
328
330
if (!bio -> init ) {
329
331
OPENSSL_PUT_ERROR (BIO , BIO_R_UNINITIALIZED );
330
332
return -2 ;
331
333
}
334
+ int ret = 0 ;
332
335
if (bio -> method -> bputs != NULL ) {
333
336
ret = bio -> method -> bputs (bio , in );
334
337
} else {
0 commit comments