diff options
author | tb <> | 2023-07-28 10:13:50 +0000 |
---|---|---|
committer | tb <> | 2023-07-28 10:13:50 +0000 |
commit | e56dd594e13ac1e9a8e37ebda000cf90e2a9ad20 (patch) | |
tree | a171add36e20e14aac1e71e60b1bf649a99adc40 /src/lib/libcrypto/bio/bss_bio.c | |
parent | 5a5bd1401f412a6edcc762b842246d253befc095 (diff) | |
download | openbsd-e56dd594e13ac1e9a8e37ebda000cf90e2a9ad20.tar.gz openbsd-e56dd594e13ac1e9a8e37ebda000cf90e2a9ad20.tar.bz2 openbsd-e56dd594e13ac1e9a8e37ebda000cf90e2a9ad20.zip |
Drop BIO_n{read,write}{,0}()
This is one of those strange things that should never have made it into
a security-oriented libraries. From BIO_s_bio.3:
.\" The following non-copying I/O functions are intentionally undocumented
.\" because they seem fragile and unused by anything:
It was used in a single place: the gorgeous ssltest. I'm not smart enough
to follow. Also:
/* WARNING: The non-copying interface is largely untested as of yet
* and may contain bugs. */
Oh, really? Into the great bitbucket in the sky you go.
ok jsing
Diffstat (limited to 'src/lib/libcrypto/bio/bss_bio.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_bio.c | 257 |
1 files changed, 2 insertions, 255 deletions
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c index d4c03abda2..9a3215a7d4 100644 --- a/src/lib/libcrypto/bio/bss_bio.c +++ b/src/lib/libcrypto/bio/bss_bio.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bss_bio.c,v 1.27 2023/07/07 19:37:53 beck Exp $ */ | 1 | /* $OpenBSD: bss_bio.c,v 1.28 2023/07/28 10:13:50 tb Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -251,85 +251,6 @@ bio_read(BIO *bio, char *buf, int size_) | |||
251 | return size; | 251 | return size; |
252 | } | 252 | } |
253 | 253 | ||
254 | /* non-copying interface: provide pointer to available data in buffer | ||
255 | * bio_nread0: return number of available bytes | ||
256 | * bio_nread: also advance index | ||
257 | * (example usage: bio_nread0(), read from buffer, bio_nread() | ||
258 | * or just bio_nread(), read from buffer) | ||
259 | */ | ||
260 | /* WARNING: The non-copying interface is largely untested as of yet | ||
261 | * and may contain bugs. */ | ||
262 | static ssize_t | ||
263 | bio_nread0(BIO *bio, char **buf) | ||
264 | { | ||
265 | struct bio_bio_st *b, *peer_b; | ||
266 | ssize_t num; | ||
267 | |||
268 | BIO_clear_retry_flags(bio); | ||
269 | |||
270 | if (!bio->init) | ||
271 | return 0; | ||
272 | |||
273 | b = bio->ptr; | ||
274 | assert(b != NULL); | ||
275 | assert(b->peer != NULL); | ||
276 | peer_b = b->peer->ptr; | ||
277 | assert(peer_b != NULL); | ||
278 | assert(peer_b->buf != NULL); | ||
279 | |||
280 | peer_b->request = 0; | ||
281 | |||
282 | if (peer_b->len == 0) { | ||
283 | char dummy; | ||
284 | |||
285 | /* avoid code duplication -- nothing available for reading */ | ||
286 | return bio_read(bio, &dummy, 1); /* returns 0 or -1 */ | ||
287 | } | ||
288 | |||
289 | num = peer_b->len; | ||
290 | if (peer_b->size < peer_b->offset + num) | ||
291 | /* no ring buffer wrap-around for non-copying interface */ | ||
292 | num = peer_b->size - peer_b->offset; | ||
293 | assert(num > 0); | ||
294 | |||
295 | if (buf != NULL) | ||
296 | *buf = peer_b->buf + peer_b->offset; | ||
297 | return num; | ||
298 | } | ||
299 | |||
300 | static ssize_t | ||
301 | bio_nread(BIO *bio, char **buf, size_t num_) | ||
302 | { | ||
303 | struct bio_bio_st *b, *peer_b; | ||
304 | ssize_t num, available; | ||
305 | |||
306 | if (num_ > SSIZE_MAX) | ||
307 | num = SSIZE_MAX; | ||
308 | else | ||
309 | num = (ssize_t)num_; | ||
310 | |||
311 | available = bio_nread0(bio, buf); | ||
312 | if (num > available) | ||
313 | num = available; | ||
314 | if (num <= 0) | ||
315 | return num; | ||
316 | |||
317 | b = bio->ptr; | ||
318 | peer_b = b->peer->ptr; | ||
319 | |||
320 | peer_b->len -= num; | ||
321 | if (peer_b->len) { | ||
322 | peer_b->offset += num; | ||
323 | assert(peer_b->offset <= peer_b->size); | ||
324 | if (peer_b->offset == peer_b->size) | ||
325 | peer_b->offset = 0; | ||
326 | } else | ||
327 | peer_b->offset = 0; | ||
328 | |||
329 | return num; | ||
330 | } | ||
331 | |||
332 | |||
333 | static int | 254 | static int |
334 | bio_write(BIO *bio, const char *buf, int num_) | 255 | bio_write(BIO *bio, const char *buf, int num_) |
335 | { | 256 | { |
@@ -402,85 +323,6 @@ bio_write(BIO *bio, const char *buf, int num_) | |||
402 | return num; | 323 | return num; |
403 | } | 324 | } |
404 | 325 | ||
405 | /* non-copying interface: provide pointer to region to write to | ||
406 | * bio_nwrite0: check how much space is available | ||
407 | * bio_nwrite: also increase length | ||
408 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() | ||
409 | * or just bio_nwrite(), write to buffer) | ||
410 | */ | ||
411 | static ssize_t | ||
412 | bio_nwrite0(BIO *bio, char **buf) | ||
413 | { | ||
414 | struct bio_bio_st *b; | ||
415 | size_t num; | ||
416 | size_t write_offset; | ||
417 | |||
418 | BIO_clear_retry_flags(bio); | ||
419 | |||
420 | if (!bio->init) | ||
421 | return 0; | ||
422 | |||
423 | b = bio->ptr; | ||
424 | |||
425 | assert(b != NULL); | ||
426 | assert(b->peer != NULL); | ||
427 | assert(b->buf != NULL); | ||
428 | |||
429 | b->request = 0; | ||
430 | if (b->closed) { | ||
431 | BIOerror(BIO_R_BROKEN_PIPE); | ||
432 | return -1; | ||
433 | } | ||
434 | |||
435 | assert(b->len <= b->size); | ||
436 | |||
437 | if (b->len == b->size) { | ||
438 | BIO_set_retry_write(bio); | ||
439 | return -1; | ||
440 | } | ||
441 | |||
442 | num = b->size - b->len; | ||
443 | write_offset = b->offset + b->len; | ||
444 | if (write_offset >= b->size) | ||
445 | write_offset -= b->size; | ||
446 | if (write_offset + num > b->size) | ||
447 | /* no ring buffer wrap-around for non-copying interface | ||
448 | * (to fulfil the promise by BIO_ctrl_get_write_guarantee, | ||
449 | * BIO_nwrite may have to be called twice) */ | ||
450 | num = b->size - write_offset; | ||
451 | |||
452 | if (buf != NULL) | ||
453 | *buf = b->buf + write_offset; | ||
454 | assert(write_offset + num <= b->size); | ||
455 | |||
456 | return num; | ||
457 | } | ||
458 | |||
459 | static ssize_t | ||
460 | bio_nwrite(BIO *bio, char **buf, size_t num_) | ||
461 | { | ||
462 | struct bio_bio_st *b; | ||
463 | ssize_t num, space; | ||
464 | |||
465 | if (num_ > SSIZE_MAX) | ||
466 | num = SSIZE_MAX; | ||
467 | else | ||
468 | num = (ssize_t)num_; | ||
469 | |||
470 | space = bio_nwrite0(bio, buf); | ||
471 | if (num > space) | ||
472 | num = space; | ||
473 | if (num <= 0) | ||
474 | return num; | ||
475 | b = bio->ptr; | ||
476 | assert(b != NULL); | ||
477 | b->len += num; | ||
478 | assert(b->len <= b->size); | ||
479 | |||
480 | return num; | ||
481 | } | ||
482 | |||
483 | |||
484 | static long | 326 | static long |
485 | bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | 327 | bio_ctrl(BIO *bio, int cmd, long num, void *ptr) |
486 | { | 328 | { |
@@ -564,28 +406,7 @@ bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
564 | ret = 1; | 406 | ret = 1; |
565 | break; | 407 | break; |
566 | 408 | ||
567 | case BIO_C_NREAD0: | 409 | /* standard CTRL codes follow */ |
568 | /* prepare for non-copying read */ | ||
569 | ret = (long) bio_nread0(bio, ptr); | ||
570 | break; | ||
571 | |||
572 | case BIO_C_NREAD: | ||
573 | /* non-copying read */ | ||
574 | ret = (long) bio_nread(bio, ptr, (size_t) num); | ||
575 | break; | ||
576 | |||
577 | case BIO_C_NWRITE0: | ||
578 | /* prepare for non-copying write */ | ||
579 | ret = (long) bio_nwrite0(bio, ptr); | ||
580 | break; | ||
581 | |||
582 | case BIO_C_NWRITE: | ||
583 | /* non-copying write */ | ||
584 | ret = (long) bio_nwrite(bio, ptr, (size_t) num); | ||
585 | break; | ||
586 | |||
587 | |||
588 | /* standard CTRL codes follow */ | ||
589 | 410 | ||
590 | case BIO_CTRL_RESET: | 411 | case BIO_CTRL_RESET: |
591 | if (b->buf != NULL) { | 412 | if (b->buf != NULL) { |
@@ -817,77 +638,3 @@ BIO_ctrl_reset_read_request(BIO *bio) | |||
817 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); | 638 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); |
818 | } | 639 | } |
819 | LCRYPTO_ALIAS(BIO_ctrl_reset_read_request); | 640 | LCRYPTO_ALIAS(BIO_ctrl_reset_read_request); |
820 | |||
821 | |||
822 | /* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now | ||
823 | * (conceivably some other BIOs could allow non-copying reads and writes too.) | ||
824 | */ | ||
825 | int | ||
826 | BIO_nread0(BIO *bio, char **buf) | ||
827 | { | ||
828 | long ret; | ||
829 | |||
830 | if (!bio->init) { | ||
831 | BIOerror(BIO_R_UNINITIALIZED); | ||
832 | return -2; | ||
833 | } | ||
834 | |||
835 | ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf); | ||
836 | if (ret > INT_MAX) | ||
837 | return INT_MAX; | ||
838 | else | ||
839 | return (int) ret; | ||
840 | } | ||
841 | LCRYPTO_ALIAS(BIO_nread0); | ||
842 | |||
843 | int | ||
844 | BIO_nread(BIO *bio, char **buf, int num) | ||
845 | { | ||
846 | int ret; | ||
847 | |||
848 | if (!bio->init) { | ||
849 | BIOerror(BIO_R_UNINITIALIZED); | ||
850 | return -2; | ||
851 | } | ||
852 | |||
853 | ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf); | ||
854 | if (ret > 0) | ||
855 | bio->num_read += ret; | ||
856 | return ret; | ||
857 | } | ||
858 | LCRYPTO_ALIAS(BIO_nread); | ||
859 | |||
860 | int | ||
861 | BIO_nwrite0(BIO *bio, char **buf) | ||
862 | { | ||
863 | long ret; | ||
864 | |||
865 | if (!bio->init) { | ||
866 | BIOerror(BIO_R_UNINITIALIZED); | ||
867 | return -2; | ||
868 | } | ||
869 | |||
870 | ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf); | ||
871 | if (ret > INT_MAX) | ||
872 | return INT_MAX; | ||
873 | else | ||
874 | return (int) ret; | ||
875 | } | ||
876 | LCRYPTO_ALIAS(BIO_nwrite0); | ||
877 | |||
878 | int | ||
879 | BIO_nwrite(BIO *bio, char **buf, int num) | ||
880 | { | ||
881 | int ret; | ||
882 | |||
883 | if (!bio->init) { | ||
884 | BIOerror(BIO_R_UNINITIALIZED); | ||
885 | return -2; | ||
886 | } | ||
887 | |||
888 | ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf); | ||
889 | if (ret > 0) | ||
890 | bio->num_write += ret; | ||
891 | return ret; | ||
892 | } | ||
893 | LCRYPTO_ALIAS(BIO_nwrite); | ||