From f15a2a43ef2df3a6131156e0a88fa44238fb034e Mon Sep 17 00:00:00 2001 From: zriback Date: Thu, 30 Jan 2025 11:41:15 -0500 Subject: [PATCH] Fix issue where file is not read correctly with Windows line endings Reviewed-by: Paul Dale Reviewed-by: Viktor Dukhovni (Merged from https://github.com/openssl/openssl/pull/26549) --- apps/prime.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/prime.c b/apps/prime.c index cbbcd4262ff..4c103e975fc 100644 --- a/apps/prime.c +++ b/apps/prime.c @@ -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; -- 2.47.2