diff options
| author | jsing <> | 2019-04-14 17:39:03 +0000 |
|---|---|---|
| committer | jsing <> | 2019-04-14 17:39:03 +0000 |
| commit | 43d312539a65f8db03988a53b94f1e6aa6e40f3c (patch) | |
| tree | 68528b9ee9a45dd6fc3f621182914eb48cd6a43c /src | |
| parent | a2c695645cf28a223a6da4cbfbdfd65c796e2dd6 (diff) | |
| download | openbsd-43d312539a65f8db03988a53b94f1e6aa6e40f3c.tar.gz openbsd-43d312539a65f8db03988a53b94f1e6aa6e40f3c.tar.bz2 openbsd-43d312539a65f8db03988a53b94f1e6aa6e40f3c.zip | |
Add input validation to BIO_read()/BIO_write().
Some bread/bwrite functions implement this themselves, while others do not.
This makes it consistent across all BIO implementations.
Addresses an issue that Guido Vranken found with his fuzzer.
ok tb@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index de039a7f5d..7ef1784e13 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bio_lib.c,v 1.28 2018/05/01 13:29:09 tb Exp $ */ | 1 | /* $OpenBSD: bio_lib.c,v 1.29 2019/04/14 17:39:03 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -250,7 +250,13 @@ BIO_read(BIO *b, void *out, int outl) | |||
| 250 | int i; | 250 | int i; |
| 251 | long (*cb)(BIO *, int, const char *, int, long, long); | 251 | long (*cb)(BIO *, int, const char *, int, long, long); |
| 252 | 252 | ||
| 253 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) { | 253 | if (b == NULL) |
| 254 | return (0); | ||
| 255 | |||
| 256 | if (out == NULL || outl <= 0) | ||
| 257 | return (0); | ||
| 258 | |||
| 259 | if (b->method == NULL || b->method->bread == NULL) { | ||
| 254 | BIOerror(BIO_R_UNSUPPORTED_METHOD); | 260 | BIOerror(BIO_R_UNSUPPORTED_METHOD); |
| 255 | return (-2); | 261 | return (-2); |
| 256 | } | 262 | } |
| @@ -273,6 +279,7 @@ BIO_read(BIO *b, void *out, int outl) | |||
| 273 | if (cb != NULL) | 279 | if (cb != NULL) |
| 274 | i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, | 280 | i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, |
| 275 | 0L, (long)i); | 281 | 0L, (long)i); |
| 282 | |||
| 276 | return (i); | 283 | return (i); |
| 277 | } | 284 | } |
| 278 | 285 | ||
| @@ -285,12 +292,15 @@ BIO_write(BIO *b, const void *in, int inl) | |||
| 285 | if (b == NULL) | 292 | if (b == NULL) |
| 286 | return (0); | 293 | return (0); |
| 287 | 294 | ||
| 288 | cb = b->callback; | 295 | if (in == NULL || inl <= 0) |
| 289 | if ((b->method == NULL) || (b->method->bwrite == NULL)) { | 296 | return (0); |
| 297 | |||
| 298 | if (b->method == NULL || b->method->bwrite == NULL) { | ||
| 290 | BIOerror(BIO_R_UNSUPPORTED_METHOD); | 299 | BIOerror(BIO_R_UNSUPPORTED_METHOD); |
| 291 | return (-2); | 300 | return (-2); |
| 292 | } | 301 | } |
| 293 | 302 | ||
| 303 | cb = b->callback; | ||
| 294 | if ((cb != NULL) && | 304 | if ((cb != NULL) && |
| 295 | ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0)) | 305 | ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0)) |
| 296 | return (i); | 306 | return (i); |
