summaryrefslogtreecommitdiff
path: root/regress/unittests/sshbuf/test_sshbuf_misc.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2019-10-09 22:59:48 +0100
committerColin Watson <cjwatson@debian.org>2019-10-09 22:59:48 +0100
commit4213eec74e74de6310c27a40c3e9759a08a73996 (patch)
treee97a6dcafc6763aea7c804e4e113c2750cb1400d /regress/unittests/sshbuf/test_sshbuf_misc.c
parent102062f825fb26a74295a1c089c00c4c4c76b68a (diff)
parentcdf1d0a9f5d18535e0a18ff34860e81a6d83aa5c (diff)
Import openssh_8.1p1.orig.tar.gz
Diffstat (limited to 'regress/unittests/sshbuf/test_sshbuf_misc.c')
-rw-r--r--regress/unittests/sshbuf/test_sshbuf_misc.c71
1 files changed, 61 insertions, 10 deletions
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
23void sshbuf_misc_tests(void); 24void sshbuf_misc_tests(void);
24 25
@@ -26,7 +27,7 @@ void
26sshbuf_misc_tests(void) 27sshbuf_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