aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-10-01 19:23:52 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-10-24 09:48:35 +0200
commit8c77a497290c675a00919c75686d03ed151c41a3 (patch)
treeb18e66473bfdccbe60d9c30af2aeee6563ab5115
parent8c8026b8922a139d67e5b3fd143ca3a3b5bbc88a (diff)
downloadlibssh-8c77a497290c675a00919c75686d03ed151c41a3.tar.gz
libssh-8c77a497290c675a00919c75686d03ed151c41a3.tar.xz
libssh-8c77a497290c675a00919c75686d03ed151c41a3.zip
tests: Fix pointer arithmetic in torture_pki_*_publickey_base64
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/unittests/torture_hashes.c12
-rw-r--r--tests/unittests/torture_pki_ecdsa.c12
-rw-r--r--tests/unittests/torture_pki_ed25519.c12
-rw-r--r--tests/unittests/torture_pki_rsa.c12
4 files changed, 32 insertions, 16 deletions
diff --git a/tests/unittests/torture_hashes.c b/tests/unittests/torture_hashes.c
index 59e23d28..57fe830b 100644
--- a/tests/unittests/torture_hashes.c
+++ b/tests/unittests/torture_hashes.c
@@ -20,15 +20,19 @@ static int setup_rsa_key(void **state)
assert_true(b64_key != NULL);
q = p = b64_key;
- while (*p != ' ') p++;
- *p = '\0';
+ while (p != NULL && *p != '\0' && *p != ' ') p++;
+ if (p != NULL) {
+ *p = '\0';
+ }
type = ssh_key_type_from_name(q);
assert_true(type == SSH_KEYTYPE_RSA);
q = ++p;
- while (*p != ' ') p++;
- *p = '\0';
+ while (p != NULL && *p != '\0' && *p != ' ') p++;
+ if (p != NULL) {
+ *p = '\0';
+ }
rc = ssh_pki_import_pubkey_base64(q, type, &key);
assert_true(rc == 0);
diff --git a/tests/unittests/torture_pki_ecdsa.c b/tests/unittests/torture_pki_ecdsa.c
index 7ef354f7..b3a76442 100644
--- a/tests/unittests/torture_pki_ecdsa.c
+++ b/tests/unittests/torture_pki_ecdsa.c
@@ -199,15 +199,19 @@ static void torture_pki_ecdsa_publickey_base64(void **state)
assert_true(key_buf != NULL);
q = p = key_buf;
- while (*p != ' ') p++;
- *p = '\0';
+ while (p != NULL && *p != '\0' && *p != ' ') p++;
+ if (p != NULL) {
+ *p = '\0';
+ }
type = ssh_key_type_from_name(q);
assert_true(type == SSH_KEYTYPE_ECDSA);
q = ++p;
- while (*p != ' ') p++;
- *p = '\0';
+ while (p != NULL && *p != '\0' && *p != ' ') p++;
+ if (p != NULL) {
+ *p = '\0';
+ }
rc = ssh_pki_import_pubkey_base64(q, type, &key);
assert_true(rc == 0);
diff --git a/tests/unittests/torture_pki_ed25519.c b/tests/unittests/torture_pki_ed25519.c
index a4b147bf..e97b426e 100644
--- a/tests/unittests/torture_pki_ed25519.c
+++ b/tests/unittests/torture_pki_ed25519.c
@@ -202,15 +202,19 @@ static void torture_pki_ed25519_publickey_base64(void **state)
assert_true(key_buf != NULL);
q = p = key_buf;
- while (*p != ' ') p++;
- *p = '\0';
+ while (p != NULL && *p != '\0' && *p != ' ') p++;
+ if (p != NULL) {
+ *p = '\0';
+ }
type = ssh_key_type_from_name(q);
assert_true(type == SSH_KEYTYPE_ED25519);
q = ++p;
- while (*p != ' ') p++;
- *p = '\0';
+ while (p != NULL && *p != '\0' && *p != ' ') p++;
+ if (p != NULL) {
+ *p = '\0';
+ }
rc = ssh_pki_import_pubkey_base64(q, type, &key);
assert_true(rc == 0);
diff --git a/tests/unittests/torture_pki_rsa.c b/tests/unittests/torture_pki_rsa.c
index 15ad6466..d90eceb7 100644
--- a/tests/unittests/torture_pki_rsa.c
+++ b/tests/unittests/torture_pki_rsa.c
@@ -277,15 +277,19 @@ static void torture_pki_rsa_publickey_base64(void **state)
assert_true(key_buf != NULL);
q = p = key_buf;
- while (*p != ' ') p++;
- *p = '\0';
+ while (p != NULL && *p != '\0' && *p != ' ') p++;
+ if (p != NULL) {
+ *p = '\0';
+ }
type = ssh_key_type_from_name(q);
assert_true(type == SSH_KEYTYPE_RSA);
q = ++p;
- while (*p != ' ') p++;
- *p = '\0';
+ while (p != NULL && *p != '\0' && *p != ' ') p++;
+ if (p != NULL) {
+ *p = '\0';
+ }
rc = ssh_pki_import_pubkey_base64(q, type, &key);
assert_true(rc == 0);