diff options
Diffstat (limited to 'regress/unittests/sshbuf')
-rw-r--r-- | regress/unittests/sshbuf/test_sshbuf_getput_basic.c | 231 | ||||
-rw-r--r-- | regress/unittests/sshbuf/test_sshbuf_getput_crypto.c | 3 | ||||
-rw-r--r-- | regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c | 8 | ||||
-rw-r--r-- | regress/unittests/sshbuf/test_sshbuf_misc.c | 71 | ||||
-rw-r--r-- | regress/unittests/sshbuf/tests.c | 2 |
5 files changed, 302 insertions, 13 deletions
diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_basic.c b/regress/unittests/sshbuf/test_sshbuf_getput_basic.c index 966e8432b..bea89881a 100644 --- a/regress/unittests/sshbuf/test_sshbuf_getput_basic.c +++ b/regress/unittests/sshbuf/test_sshbuf_getput_basic.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_sshbuf_getput_basic.c,v 1.1 2014/04/30 05:32:00 djm Exp $ */ | 1 | /* $OpenBSD: test_sshbuf_getput_basic.c,v 1.2 2019/07/14 23:33:19 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Regress test for sshbuf.h buffer API | 3 | * Regress test for sshbuf.h buffer API |
4 | * | 4 | * |
@@ -481,4 +481,233 @@ sshbuf_getput_basic_tests(void) | |||
481 | ASSERT_MEM_EQ(sshbuf_ptr(p1), bn_exp3, sizeof(bn_exp3)); | 481 | ASSERT_MEM_EQ(sshbuf_ptr(p1), bn_exp3, sizeof(bn_exp3)); |
482 | sshbuf_free(p1); | 482 | sshbuf_free(p1); |
483 | TEST_DONE(); | 483 | TEST_DONE(); |
484 | |||
485 | TEST_START("sshbuf_peek_u64"); | ||
486 | p1 = sshbuf_new(); | ||
487 | ASSERT_PTR_NE(p1, NULL); | ||
488 | ASSERT_INT_EQ(sshbuf_put(p1, x, sizeof(x)), 0); | ||
489 | ASSERT_INT_EQ(sshbuf_peek_u64(p1, 0, &v64), 0); | ||
490 | ASSERT_U64_EQ(v64, 0x1122334455667788ULL); | ||
491 | ASSERT_INT_EQ(sshbuf_peek_u64(p1, 2, &v64), 0); | ||
492 | ASSERT_U64_EQ(v64, 0x3344556677880099ULL); | ||
493 | ASSERT_INT_EQ(sshbuf_peek_u64(p1, 3, &v64), SSH_ERR_MESSAGE_INCOMPLETE); | ||
494 | ASSERT_INT_EQ(sshbuf_peek_u64(p1, sizeof(x), &v64), | ||
495 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
496 | ASSERT_INT_EQ(sshbuf_peek_u64(p1, 1000, &v64), | ||
497 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
498 | sshbuf_free(p1); | ||
499 | TEST_DONE(); | ||
500 | |||
501 | TEST_START("sshbuf_peek_u32"); | ||
502 | p1 = sshbuf_new(); | ||
503 | ASSERT_PTR_NE(p1, NULL); | ||
504 | ASSERT_INT_EQ(sshbuf_put(p1, x, sizeof(x)), 0); | ||
505 | ASSERT_INT_EQ(sshbuf_peek_u32(p1, 0, &v32), 0); | ||
506 | ASSERT_U32_EQ(v32, 0x11223344); | ||
507 | ASSERT_INT_EQ(sshbuf_peek_u32(p1, 6, &v32), 0); | ||
508 | ASSERT_U32_EQ(v32, 0x77880099); | ||
509 | ASSERT_INT_EQ(sshbuf_peek_u32(p1, 7, &v32), SSH_ERR_MESSAGE_INCOMPLETE); | ||
510 | ASSERT_INT_EQ(sshbuf_peek_u32(p1, sizeof(x), &v32), | ||
511 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
512 | ASSERT_INT_EQ(sshbuf_peek_u32(p1, 1000, &v32), | ||
513 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
514 | sshbuf_free(p1); | ||
515 | TEST_DONE(); | ||
516 | |||
517 | TEST_START("sshbuf_peek_u16"); | ||
518 | p1 = sshbuf_new(); | ||
519 | ASSERT_PTR_NE(p1, NULL); | ||
520 | ASSERT_INT_EQ(sshbuf_put(p1, x, sizeof(x)), 0); | ||
521 | ASSERT_INT_EQ(sshbuf_peek_u16(p1, 0, &v16), 0); | ||
522 | ASSERT_U16_EQ(v16, 0x1122); | ||
523 | ASSERT_INT_EQ(sshbuf_peek_u16(p1, 8, &v16), 0); | ||
524 | ASSERT_U16_EQ(v16, 0x99); | ||
525 | ASSERT_INT_EQ(sshbuf_peek_u16(p1, 9, &v16), SSH_ERR_MESSAGE_INCOMPLETE); | ||
526 | ASSERT_INT_EQ(sshbuf_peek_u16(p1, sizeof(x), &v16), | ||
527 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
528 | ASSERT_INT_EQ(sshbuf_peek_u16(p1, 1000, &v16), | ||
529 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
530 | sshbuf_free(p1); | ||
531 | TEST_DONE(); | ||
532 | |||
533 | TEST_START("sshbuf_peek_u8"); | ||
534 | p1 = sshbuf_new(); | ||
535 | ASSERT_PTR_NE(p1, NULL); | ||
536 | ASSERT_INT_EQ(sshbuf_put(p1, x, sizeof(x)), 0); | ||
537 | ASSERT_INT_EQ(sshbuf_peek_u8(p1, 0, &v8), 0); | ||
538 | ASSERT_U8_EQ(v8, 0x11); | ||
539 | ASSERT_INT_EQ(sshbuf_peek_u8(p1, 9, &v8), 0); | ||
540 | ASSERT_U8_EQ(v8, 0x99); | ||
541 | ASSERT_INT_EQ(sshbuf_peek_u8(p1, sizeof(x), &v8), | ||
542 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
543 | ASSERT_INT_EQ(sshbuf_peek_u8(p1, 1000, &v8), | ||
544 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
545 | sshbuf_free(p1); | ||
546 | TEST_DONE(); | ||
547 | |||
548 | TEST_START("sshbuf_poke_u64"); | ||
549 | p1 = sshbuf_new(); | ||
550 | ASSERT_PTR_NE(p1, NULL); | ||
551 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
552 | /* poke at start of buffer */ | ||
553 | ASSERT_INT_EQ(sshbuf_poke_u64(p1, 0, 0xa1b2c3d4e5f60718ULL), 0); | ||
554 | s2 = sshbuf_dtob16(p1); | ||
555 | ASSERT_PTR_NE(s2, NULL); | ||
556 | ASSERT_STRING_EQ(s2, "a1b2c3d4e5f607180000"); | ||
557 | free(s2); | ||
558 | sshbuf_reset(p1); | ||
559 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
560 | /* poke aligned with end of buffer */ | ||
561 | ASSERT_INT_EQ(sshbuf_poke_u64(p1, 2, 0xa1b2c3d4e5f60718ULL), 0); | ||
562 | s2 = sshbuf_dtob16(p1); | ||
563 | ASSERT_PTR_NE(s2, NULL); | ||
564 | ASSERT_STRING_EQ(s2, "0000a1b2c3d4e5f60718"); | ||
565 | free(s2); | ||
566 | sshbuf_reset(p1); | ||
567 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
568 | /* poke past end of buffer */ | ||
569 | ASSERT_INT_EQ(sshbuf_poke_u64(p1, 3, 0xa1b2c3d4e5f60718ULL), | ||
570 | SSH_ERR_NO_BUFFER_SPACE); | ||
571 | ASSERT_INT_EQ(sshbuf_poke_u64(p1, 10, 0xa1b2c3d4e5f60718ULL), | ||
572 | SSH_ERR_NO_BUFFER_SPACE); | ||
573 | ASSERT_INT_EQ(sshbuf_poke_u64(p1, 1000, 0xa1b2c3d4e5f60718ULL), | ||
574 | SSH_ERR_NO_BUFFER_SPACE); | ||
575 | /* ensure failed pokes do not modify buffer */ | ||
576 | s2 = sshbuf_dtob16(p1); | ||
577 | ASSERT_PTR_NE(s2, NULL); | ||
578 | ASSERT_STRING_EQ(s2, "00000000000000000000"); | ||
579 | sshbuf_free(p1); | ||
580 | TEST_DONE(); | ||
581 | |||
582 | TEST_START("sshbuf_poke_u32"); | ||
583 | p1 = sshbuf_new(); | ||
584 | ASSERT_PTR_NE(p1, NULL); | ||
585 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
586 | /* poke at start of buffer */ | ||
587 | ASSERT_INT_EQ(sshbuf_poke_u32(p1, 0, 0xa1b2c3d4), 0); | ||
588 | s2 = sshbuf_dtob16(p1); | ||
589 | ASSERT_PTR_NE(s2, NULL); | ||
590 | ASSERT_STRING_EQ(s2, "a1b2c3d4000000000000"); | ||
591 | free(s2); | ||
592 | sshbuf_reset(p1); | ||
593 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
594 | /* poke aligned with end of buffer */ | ||
595 | ASSERT_INT_EQ(sshbuf_poke_u32(p1, 6, 0xa1b2c3d4), 0); | ||
596 | s2 = sshbuf_dtob16(p1); | ||
597 | ASSERT_PTR_NE(s2, NULL); | ||
598 | ASSERT_STRING_EQ(s2, "000000000000a1b2c3d4"); | ||
599 | free(s2); | ||
600 | sshbuf_reset(p1); | ||
601 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
602 | /* poke past end of buffer */ | ||
603 | ASSERT_INT_EQ(sshbuf_poke_u32(p1, 7, 0xa1b2c3d4), | ||
604 | SSH_ERR_NO_BUFFER_SPACE); | ||
605 | ASSERT_INT_EQ(sshbuf_poke_u32(p1, 10, 0xa1b2c3d4), | ||
606 | SSH_ERR_NO_BUFFER_SPACE); | ||
607 | ASSERT_INT_EQ(sshbuf_poke_u32(p1, 1000, 0xa1b2c3d4), | ||
608 | SSH_ERR_NO_BUFFER_SPACE); | ||
609 | /* ensure failed pokes do not modify buffer */ | ||
610 | s2 = sshbuf_dtob16(p1); | ||
611 | ASSERT_PTR_NE(s2, NULL); | ||
612 | ASSERT_STRING_EQ(s2, "00000000000000000000"); | ||
613 | sshbuf_free(p1); | ||
614 | TEST_DONE(); | ||
615 | |||
616 | TEST_START("sshbuf_poke_u16"); | ||
617 | p1 = sshbuf_new(); | ||
618 | ASSERT_PTR_NE(p1, NULL); | ||
619 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
620 | /* poke at start of buffer */ | ||
621 | ASSERT_INT_EQ(sshbuf_poke_u16(p1, 0, 0xa1b2), 0); | ||
622 | s2 = sshbuf_dtob16(p1); | ||
623 | ASSERT_PTR_NE(s2, NULL); | ||
624 | ASSERT_STRING_EQ(s2, "a1b20000000000000000"); | ||
625 | free(s2); | ||
626 | sshbuf_reset(p1); | ||
627 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
628 | /* poke aligned with end of buffer */ | ||
629 | ASSERT_INT_EQ(sshbuf_poke_u16(p1, 8, 0xa1b2), 0); | ||
630 | s2 = sshbuf_dtob16(p1); | ||
631 | ASSERT_PTR_NE(s2, NULL); | ||
632 | ASSERT_STRING_EQ(s2, "0000000000000000a1b2"); | ||
633 | free(s2); | ||
634 | sshbuf_reset(p1); | ||
635 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
636 | /* poke past end of buffer */ | ||
637 | ASSERT_INT_EQ(sshbuf_poke_u16(p1, 9, 0xa1b2), | ||
638 | SSH_ERR_NO_BUFFER_SPACE); | ||
639 | ASSERT_INT_EQ(sshbuf_poke_u16(p1, 10, 0xa1b2), | ||
640 | SSH_ERR_NO_BUFFER_SPACE); | ||
641 | ASSERT_INT_EQ(sshbuf_poke_u16(p1, 1000, 0xa1b2), | ||
642 | SSH_ERR_NO_BUFFER_SPACE); | ||
643 | /* ensure failed pokes do not modify buffer */ | ||
644 | s2 = sshbuf_dtob16(p1); | ||
645 | ASSERT_PTR_NE(s2, NULL); | ||
646 | ASSERT_STRING_EQ(s2, "00000000000000000000"); | ||
647 | sshbuf_free(p1); | ||
648 | TEST_DONE(); | ||
649 | |||
650 | TEST_START("sshbuf_poke_u8"); | ||
651 | p1 = sshbuf_new(); | ||
652 | ASSERT_PTR_NE(p1, NULL); | ||
653 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
654 | /* poke at start of buffer */ | ||
655 | ASSERT_INT_EQ(sshbuf_poke_u8(p1, 0, 0xa1), 0); | ||
656 | s2 = sshbuf_dtob16(p1); | ||
657 | ASSERT_PTR_NE(s2, NULL); | ||
658 | ASSERT_STRING_EQ(s2, "a1000000000000000000"); | ||
659 | free(s2); | ||
660 | sshbuf_reset(p1); | ||
661 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
662 | /* poke aligned with end of buffer */ | ||
663 | ASSERT_INT_EQ(sshbuf_poke_u8(p1, 9, 0xa1), 0); | ||
664 | s2 = sshbuf_dtob16(p1); | ||
665 | ASSERT_PTR_NE(s2, NULL); | ||
666 | ASSERT_STRING_EQ(s2, "000000000000000000a1"); | ||
667 | free(s2); | ||
668 | sshbuf_reset(p1); | ||
669 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
670 | /* poke past end of buffer */ | ||
671 | ASSERT_INT_EQ(sshbuf_poke_u8(p1, 10, 0xa1), SSH_ERR_NO_BUFFER_SPACE); | ||
672 | ASSERT_INT_EQ(sshbuf_poke_u8(p1, 1000, 0xa1), SSH_ERR_NO_BUFFER_SPACE); | ||
673 | /* ensure failed pokes do not modify buffer */ | ||
674 | s2 = sshbuf_dtob16(p1); | ||
675 | ASSERT_PTR_NE(s2, NULL); | ||
676 | ASSERT_STRING_EQ(s2, "00000000000000000000"); | ||
677 | sshbuf_free(p1); | ||
678 | TEST_DONE(); | ||
679 | |||
680 | TEST_START("sshbuf_poke"); | ||
681 | p1 = sshbuf_new(); | ||
682 | ASSERT_PTR_NE(p1, NULL); | ||
683 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
684 | /* poke at start of buffer */ | ||
685 | ASSERT_INT_EQ(sshbuf_poke(p1, 0, "hello!", 6), 0); | ||
686 | s2 = sshbuf_dtob16(p1); | ||
687 | ASSERT_PTR_NE(s2, NULL); | ||
688 | ASSERT_STRING_EQ(s2, "68656c6c6f2100000000"); | ||
689 | free(s2); | ||
690 | sshbuf_reset(p1); | ||
691 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
692 | /* poke aligned with end of buffer */ | ||
693 | ASSERT_INT_EQ(sshbuf_poke(p1, 4, "hello!", 6), 0); | ||
694 | s2 = sshbuf_dtob16(p1); | ||
695 | ASSERT_PTR_NE(s2, NULL); | ||
696 | ASSERT_STRING_EQ(s2, "0000000068656c6c6f21"); | ||
697 | free(s2); | ||
698 | sshbuf_reset(p1); | ||
699 | ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0); | ||
700 | /* poke past end of buffer */ | ||
701 | ASSERT_INT_EQ(sshbuf_poke(p1, 7, "hello!", 6), | ||
702 | SSH_ERR_NO_BUFFER_SPACE); | ||
703 | ASSERT_INT_EQ(sshbuf_poke(p1, 10, "hello!", 6), | ||
704 | SSH_ERR_NO_BUFFER_SPACE); | ||
705 | ASSERT_INT_EQ(sshbuf_poke(p1, 1000, "hello!", 6), | ||
706 | SSH_ERR_NO_BUFFER_SPACE); | ||
707 | /* ensure failed pokes do not modify buffer */ | ||
708 | s2 = sshbuf_dtob16(p1); | ||
709 | ASSERT_PTR_NE(s2, NULL); | ||
710 | ASSERT_STRING_EQ(s2, "00000000000000000000"); | ||
711 | sshbuf_free(p1); | ||
712 | TEST_DONE(); | ||
484 | } | 713 | } |
diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c b/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c index 5d39e63e1..492b3bdf0 100644 --- a/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c +++ b/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c | |||
@@ -7,6 +7,8 @@ | |||
7 | 7 | ||
8 | #include "includes.h" | 8 | #include "includes.h" |
9 | 9 | ||
10 | #ifdef WITH_OPENSSL | ||
11 | |||
10 | #include <sys/types.h> | 12 | #include <sys/types.h> |
11 | #include <sys/param.h> | 13 | #include <sys/param.h> |
12 | #include <stdio.h> | 14 | #include <stdio.h> |
@@ -276,3 +278,4 @@ sshbuf_getput_crypto_tests(void) | |||
276 | #endif | 278 | #endif |
277 | } | 279 | } |
278 | 280 | ||
281 | #endif /* WITH_OPENSSL */ | ||
diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c b/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c index ca06bfb00..1ca30be97 100644 --- a/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c +++ b/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c | |||
@@ -32,10 +32,12 @@ static void | |||
32 | attempt_parse_blob(u_char *blob, size_t len) | 32 | attempt_parse_blob(u_char *blob, size_t len) |
33 | { | 33 | { |
34 | struct sshbuf *p1; | 34 | struct sshbuf *p1; |
35 | #ifdef WITH_OPENSSL | ||
35 | BIGNUM *bn; | 36 | BIGNUM *bn; |
36 | #if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) | 37 | #if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) |
37 | EC_KEY *eck; | 38 | EC_KEY *eck; |
38 | #endif | 39 | #endif /* defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) */ |
40 | #endif /* WITH_OPENSSL */ | ||
39 | u_char *s; | 41 | u_char *s; |
40 | size_t l; | 42 | size_t l; |
41 | u_int8_t u8; | 43 | u_int8_t u8; |
@@ -54,6 +56,7 @@ attempt_parse_blob(u_char *blob, size_t len) | |||
54 | bzero(s, l); | 56 | bzero(s, l); |
55 | free(s); | 57 | free(s); |
56 | } | 58 | } |
59 | #ifdef WITH_OPENSSL | ||
57 | bn = NULL; | 60 | bn = NULL; |
58 | sshbuf_get_bignum2(p1, &bn); | 61 | sshbuf_get_bignum2(p1, &bn); |
59 | BN_clear_free(bn); | 62 | BN_clear_free(bn); |
@@ -62,7 +65,8 @@ attempt_parse_blob(u_char *blob, size_t len) | |||
62 | ASSERT_PTR_NE(eck, NULL); | 65 | ASSERT_PTR_NE(eck, NULL); |
63 | sshbuf_get_eckey(p1, eck); | 66 | sshbuf_get_eckey(p1, eck); |
64 | EC_KEY_free(eck); | 67 | EC_KEY_free(eck); |
65 | #endif | 68 | #endif /* defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) */ |
69 | #endif /* WITH_OPENSSL */ | ||
66 | sshbuf_free(p1); | 70 | sshbuf_free(p1); |
67 | } | 71 | } |
68 | 72 | ||
diff --git a/regress/unittests/sshbuf/test_sshbuf_misc.c b/regress/unittests/sshbuf/test_sshbuf_misc.c index 762a6c31c..c53db937f 100644 --- a/regress/unittests/sshbuf/test_sshbuf_misc.c +++ b/regress/unittests/sshbuf/test_sshbuf_misc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_sshbuf_misc.c,v 1.2 2016/05/03 13:48:33 djm Exp $ */ | 1 | /* $OpenBSD: test_sshbuf_misc.c,v 1.4 2019/07/16 22:16:49 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Regress test for sshbuf.h buffer API | 3 | * Regress test for sshbuf.h buffer API |
4 | * | 4 | * |
@@ -19,6 +19,7 @@ | |||
19 | #include "../test_helper/test_helper.h" | 19 | #include "../test_helper/test_helper.h" |
20 | 20 | ||
21 | #include "sshbuf.h" | 21 | #include "sshbuf.h" |
22 | #include "ssherr.h" | ||
22 | 23 | ||
23 | void sshbuf_misc_tests(void); | 24 | void sshbuf_misc_tests(void); |
24 | 25 | ||
@@ -26,7 +27,7 @@ void | |||
26 | sshbuf_misc_tests(void) | 27 | sshbuf_misc_tests(void) |
27 | { | 28 | { |
28 | struct sshbuf *p1; | 29 | struct sshbuf *p1; |
29 | char tmp[512], *p; | 30 | char tmp[512], msg[] = "imploring ping silence ping over", *p; |
30 | FILE *out; | 31 | FILE *out; |
31 | size_t sz; | 32 | size_t sz; |
32 | 33 | ||
@@ -60,48 +61,48 @@ sshbuf_misc_tests(void) | |||
60 | sshbuf_free(p1); | 61 | sshbuf_free(p1); |
61 | TEST_DONE(); | 62 | TEST_DONE(); |
62 | 63 | ||
63 | TEST_START("sshbuf_dtob64 len 1"); | 64 | TEST_START("sshbuf_dtob64_string len 1"); |
64 | p1 = sshbuf_new(); | 65 | p1 = sshbuf_new(); |
65 | ASSERT_PTR_NE(p1, NULL); | 66 | ASSERT_PTR_NE(p1, NULL); |
66 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); | 67 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); |
67 | p = sshbuf_dtob64(p1); | 68 | p = sshbuf_dtob64_string(p1, 0); |
68 | ASSERT_PTR_NE(p, NULL); | 69 | ASSERT_PTR_NE(p, NULL); |
69 | ASSERT_STRING_EQ(p, "EQ=="); | 70 | ASSERT_STRING_EQ(p, "EQ=="); |
70 | free(p); | 71 | free(p); |
71 | sshbuf_free(p1); | 72 | sshbuf_free(p1); |
72 | TEST_DONE(); | 73 | TEST_DONE(); |
73 | 74 | ||
74 | TEST_START("sshbuf_dtob64 len 2"); | 75 | TEST_START("sshbuf_dtob64_string len 2"); |
75 | p1 = sshbuf_new(); | 76 | p1 = sshbuf_new(); |
76 | ASSERT_PTR_NE(p1, NULL); | 77 | ASSERT_PTR_NE(p1, NULL); |
77 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); | 78 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); |
78 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x22), 0); | 79 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x22), 0); |
79 | p = sshbuf_dtob64(p1); | 80 | p = sshbuf_dtob64_string(p1, 0); |
80 | ASSERT_PTR_NE(p, NULL); | 81 | ASSERT_PTR_NE(p, NULL); |
81 | ASSERT_STRING_EQ(p, "ESI="); | 82 | ASSERT_STRING_EQ(p, "ESI="); |
82 | free(p); | 83 | free(p); |
83 | sshbuf_free(p1); | 84 | sshbuf_free(p1); |
84 | TEST_DONE(); | 85 | TEST_DONE(); |
85 | 86 | ||
86 | TEST_START("sshbuf_dtob64 len 3"); | 87 | TEST_START("sshbuf_dtob64_string len 3"); |
87 | p1 = sshbuf_new(); | 88 | p1 = sshbuf_new(); |
88 | ASSERT_PTR_NE(p1, NULL); | 89 | ASSERT_PTR_NE(p1, NULL); |
89 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); | 90 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); |
90 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x22), 0); | 91 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x22), 0); |
91 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x33), 0); | 92 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x33), 0); |
92 | p = sshbuf_dtob64(p1); | 93 | p = sshbuf_dtob64_string(p1, 0); |
93 | ASSERT_PTR_NE(p, NULL); | 94 | ASSERT_PTR_NE(p, NULL); |
94 | ASSERT_STRING_EQ(p, "ESIz"); | 95 | ASSERT_STRING_EQ(p, "ESIz"); |
95 | free(p); | 96 | free(p); |
96 | sshbuf_free(p1); | 97 | sshbuf_free(p1); |
97 | TEST_DONE(); | 98 | TEST_DONE(); |
98 | 99 | ||
99 | TEST_START("sshbuf_dtob64 len 8191"); | 100 | TEST_START("sshbuf_dtob64_string len 8191"); |
100 | p1 = sshbuf_new(); | 101 | p1 = sshbuf_new(); |
101 | ASSERT_PTR_NE(p1, NULL); | 102 | ASSERT_PTR_NE(p1, NULL); |
102 | ASSERT_INT_EQ(sshbuf_reserve(p1, 8192, NULL), 0); | 103 | ASSERT_INT_EQ(sshbuf_reserve(p1, 8192, NULL), 0); |
103 | bzero(sshbuf_mutable_ptr(p1), 8192); | 104 | bzero(sshbuf_mutable_ptr(p1), 8192); |
104 | p = sshbuf_dtob64(p1); | 105 | p = sshbuf_dtob64_string(p1, 0); |
105 | ASSERT_PTR_NE(p, NULL); | 106 | ASSERT_PTR_NE(p, NULL); |
106 | ASSERT_SIZE_T_EQ(strlen(p), ((8191 + 2) / 3) * 4); | 107 | ASSERT_SIZE_T_EQ(strlen(p), ((8191 + 2) / 3) * 4); |
107 | free(p); | 108 | free(p); |
@@ -163,5 +164,55 @@ sshbuf_misc_tests(void) | |||
163 | ASSERT_PTR_EQ(p, NULL); | 164 | ASSERT_PTR_EQ(p, NULL); |
164 | sshbuf_free(p1); | 165 | sshbuf_free(p1); |
165 | TEST_DONE(); | 166 | TEST_DONE(); |
167 | |||
168 | TEST_START("sshbuf_cmp"); | ||
169 | p1 = sshbuf_from(msg, sizeof(msg) - 1); | ||
170 | ASSERT_PTR_NE(p1, NULL); | ||
171 | ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "i", 1), 0); | ||
172 | ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "j", 1), SSH_ERR_INVALID_FORMAT); | ||
173 | ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "imploring", 9), 0); | ||
174 | ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "implored", 9), SSH_ERR_INVALID_FORMAT); | ||
175 | ASSERT_INT_EQ(sshbuf_cmp(p1, 10, "ping", 4), 0); | ||
176 | ASSERT_INT_EQ(sshbuf_cmp(p1, 10, "ring", 4), SSH_ERR_INVALID_FORMAT); | ||
177 | ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "over", 4), 0); | ||
178 | ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "rove", 4), SSH_ERR_INVALID_FORMAT); | ||
179 | ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "overt", 5), | ||
180 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
181 | ASSERT_INT_EQ(sshbuf_cmp(p1, 32, "ping", 4), | ||
182 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
183 | ASSERT_INT_EQ(sshbuf_cmp(p1, 1000, "silence", 7), | ||
184 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
185 | ASSERT_INT_EQ(sshbuf_cmp(p1, 0, msg, sizeof(msg) - 1), 0); | ||
186 | TEST_DONE(); | ||
187 | |||
188 | TEST_START("sshbuf_find"); | ||
189 | p1 = sshbuf_from(msg, sizeof(msg) - 1); | ||
190 | ASSERT_PTR_NE(p1, NULL); | ||
191 | ASSERT_INT_EQ(sshbuf_find(p1, 0, "i", 1, &sz), 0); | ||
192 | ASSERT_SIZE_T_EQ(sz, 0); | ||
193 | ASSERT_INT_EQ(sshbuf_find(p1, 0, "j", 1, &sz), SSH_ERR_INVALID_FORMAT); | ||
194 | ASSERT_INT_EQ(sshbuf_find(p1, 0, "imploring", 9, &sz), 0); | ||
195 | ASSERT_SIZE_T_EQ(sz, 0); | ||
196 | ASSERT_INT_EQ(sshbuf_find(p1, 0, "implored", 9, &sz), | ||
197 | SSH_ERR_INVALID_FORMAT); | ||
198 | ASSERT_INT_EQ(sshbuf_find(p1, 3, "ping", 4, &sz), 0); | ||
199 | ASSERT_SIZE_T_EQ(sz, 10); | ||
200 | ASSERT_INT_EQ(sshbuf_find(p1, 11, "ping", 4, &sz), 0); | ||
201 | ASSERT_SIZE_T_EQ(sz, 23); | ||
202 | ASSERT_INT_EQ(sshbuf_find(p1, 20, "over", 4, &sz), 0); | ||
203 | ASSERT_SIZE_T_EQ(sz, 28); | ||
204 | ASSERT_INT_EQ(sshbuf_find(p1, 28, "over", 4, &sz), 0); | ||
205 | ASSERT_SIZE_T_EQ(sz, 28); | ||
206 | ASSERT_INT_EQ(sshbuf_find(p1, 28, "rove", 4, &sz), | ||
207 | SSH_ERR_INVALID_FORMAT); | ||
208 | ASSERT_INT_EQ(sshbuf_find(p1, 28, "overt", 5, &sz), | ||
209 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
210 | ASSERT_INT_EQ(sshbuf_find(p1, 32, "ping", 4, &sz), | ||
211 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
212 | ASSERT_INT_EQ(sshbuf_find(p1, 1000, "silence", 7, &sz), | ||
213 | SSH_ERR_MESSAGE_INCOMPLETE); | ||
214 | ASSERT_INT_EQ(sshbuf_find(p1, 0, msg + 1, sizeof(msg) - 2, &sz), 0); | ||
215 | ASSERT_SIZE_T_EQ(sz, 1); | ||
216 | TEST_DONE(); | ||
166 | } | 217 | } |
167 | 218 | ||
diff --git a/regress/unittests/sshbuf/tests.c b/regress/unittests/sshbuf/tests.c index 1557e4342..29916a10b 100644 --- a/regress/unittests/sshbuf/tests.c +++ b/regress/unittests/sshbuf/tests.c | |||
@@ -20,7 +20,9 @@ tests(void) | |||
20 | { | 20 | { |
21 | sshbuf_tests(); | 21 | sshbuf_tests(); |
22 | sshbuf_getput_basic_tests(); | 22 | sshbuf_getput_basic_tests(); |
23 | #ifdef WITH_OPENSSL | ||
23 | sshbuf_getput_crypto_tests(); | 24 | sshbuf_getput_crypto_tests(); |
25 | #endif | ||
24 | sshbuf_misc_tests(); | 26 | sshbuf_misc_tests(); |
25 | sshbuf_fuzz_tests(); | 27 | sshbuf_fuzz_tests(); |
26 | sshbuf_getput_fuzz_tests(); | 28 | sshbuf_getput_fuzz_tests(); |