Fix a -Warray-bounds gcc warning in OPENSSL_DIR_read
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Sun, 3 Nov 2019 16:34:23 +0000 (17:34 +0100)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Sat, 9 Nov 2019 09:49:34 +0000 (10:49 +0100)
'__builtin_strncpy' offset [275, 4095] from the object at
'direntry' is out of the bounds of referenced subobject 'd_name'
with type 'char[256]' at offset 19

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10343)

crypto/LPdir_unix.c

index f2c86191153e0a0c22e7a43cd138ad742b9dce76..ddf68b576f8823503664e8191edc7cf5b63d1fea 100644 (file)
@@ -131,9 +131,8 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
         return 0;
     }
 
-    strncpy((*ctx)->entry_name, direntry->d_name,
-            sizeof((*ctx)->entry_name) - 1);
-    (*ctx)->entry_name[sizeof((*ctx)->entry_name) - 1] = '\0';
+    OPENSSL_strlcpy((*ctx)->entry_name, direntry->d_name,
+                    sizeof((*ctx)->entry_name));
 #ifdef __VMS
     if ((*ctx)->expect_file_generations) {
         char *p = (*ctx)->entry_name + strlen((*ctx)->entry_name);