summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2016-05-03 13:48:33 +0000
committerDamien Miller <djm@mindrot.org>2016-06-08 11:40:38 +1000
commit01cabf10adc7676cba5f40536a34d3b246edb73f (patch)
tree9c18b4177eb9809c68362f1514509edb53944a38
parent6915f1698e3d1dd4e22eac20f435e1dfc1d46372 (diff)
upstream commit
unit tests for sshbuf_dup_string() Upstream-Regress-ID: 7521ff150dc7f20511d1c2c48fd3318e5850a96d
-rw-r--r--regress/unittests/sshbuf/test_sshbuf_misc.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/regress/unittests/sshbuf/test_sshbuf_misc.c b/regress/unittests/sshbuf/test_sshbuf_misc.c
index f155491a0..762a6c31c 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.1 2014/04/30 05:32:00 djm Exp $ */ 1/* $OpenBSD: test_sshbuf_misc.c,v 1.2 2016/05/03 13:48:33 djm Exp $ */
2/* 2/*
3 * Regress test for sshbuf.h buffer API 3 * Regress test for sshbuf.h buffer API
4 * 4 *
@@ -134,5 +134,34 @@ sshbuf_misc_tests(void)
134 ASSERT_U32_EQ(PEEK_U32(sshbuf_ptr(p1)), 0xd00fd00f); 134 ASSERT_U32_EQ(PEEK_U32(sshbuf_ptr(p1)), 0xd00fd00f);
135 sshbuf_free(p1); 135 sshbuf_free(p1);
136 TEST_DONE(); 136 TEST_DONE();
137
138 TEST_START("sshbuf_dup_string");
139 p1 = sshbuf_new();
140 ASSERT_PTR_NE(p1, NULL);
141 /* Check empty buffer */
142 p = sshbuf_dup_string(p1);
143 ASSERT_PTR_NE(p, NULL);
144 ASSERT_SIZE_T_EQ(strlen(p), 0);
145 free(p);
146 /* Check buffer with string */
147 ASSERT_INT_EQ(sshbuf_put(p1, "quad1", strlen("quad1")), 0);
148 p = sshbuf_dup_string(p1);
149 ASSERT_PTR_NE(p, NULL);
150 ASSERT_SIZE_T_EQ(strlen(p), strlen("quad1"));
151 ASSERT_STRING_EQ(p, "quad1");
152 free(p);
153 /* Check buffer with terminating nul */
154 ASSERT_INT_EQ(sshbuf_put(p1, "\0", 1), 0);
155 p = sshbuf_dup_string(p1);
156 ASSERT_PTR_NE(p, NULL);
157 ASSERT_SIZE_T_EQ(strlen(p), strlen("quad1"));
158 ASSERT_STRING_EQ(p, "quad1");
159 free(p);
160 /* Check buffer with data after nul (expect failure) */
161 ASSERT_INT_EQ(sshbuf_put(p1, "quad2", strlen("quad2")), 0);
162 p = sshbuf_dup_string(p1);
163 ASSERT_PTR_EQ(p, NULL);
164 sshbuf_free(p1);
165 TEST_DONE();
137} 166}
138 167