]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
coverity #1486532: fix potential NULL dereference in test_mk_file_path()
authorTomas Mraz <tomas@openssl.org>
Mon, 28 Jun 2021 15:13:31 +0000 (17:13 +0200)
committerTomas Mraz <tomas@openssl.org>
Tue, 29 Jun 2021 16:41:46 +0000 (18:41 +0200)
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15942)

test/testutil/driver.c

index f91d1ab9325c7da1d5fca19a6f8cc3b2d29616b3..8568a51fd7075dded3bf1acf1e31eda3f405ffc9 100644 (file)
@@ -439,11 +439,12 @@ char *test_mk_file_path(const char *dir, const char *file)
     char *dir_end;
     char dir_end_sep;
 # endif
-    size_t len = strlen(dir) + strlen(sep) + strlen(file) + 1;
+    size_t dirlen = dir != NULL ? strlen(dir) : 0;
+    size_t len = dirlen + strlen(sep) + strlen(file) + 1;
     char *full_file = OPENSSL_zalloc(len);
 
     if (full_file != NULL) {
-        if (dir != NULL && dir[0] != '\0') {
+        if (dir != NULL && dirlen > 0) {
             OPENSSL_strlcpy(full_file, dir, len);
 # ifdef OPENSSL_SYS_VMS
             /*