]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix issue where file is not read correctly with Windows line endings
authorzriback <zacharythecdr@gmail.com>
Thu, 30 Jan 2025 16:41:15 +0000 (11:41 -0500)
committerViktor Dukhovni <openssl-users@dukhovni.org>
Tue, 29 Apr 2025 04:17:06 +0000 (14:17 +1000)
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26549)

apps/prime.c

index cbbcd4262ff45da57fae28a9d67fcbfc7221a56a..4c103e975fc5ba5477700d9b1e8bc94ef705c031 100644 (file)
@@ -172,8 +172,10 @@ opthelp:
                         file_read_buf = (char *)realloc(file_read_buf, BUFSIZE + total_read);
                 }
 
-                /* Trim trailing newline if present */
-                if (file_read_buf[total_read - 1] == '\n')
+                /* Deal with Unix and Windows line endings */
+                if (file_read_buf[total_read - 2] == '\r')
+                    file_read_buf[total_read - 2] = '\0';
+                else if (file_read_buf[total_read - 1] == '\n')
                     file_read_buf[total_read - 1] = '\0';
 
                 check_val = file_read_buf;