} else {
for ( ; *argv; argv++) {
char *check_val;
+ int bytes_read = 0;
int total_read = 0;
int r;
goto end;
}
- int i;
file_read_buf = (char *)app_malloc(BUFSIZE, "File read buffer");
while (BIO_pending(in) || !BIO_eof(in)) {
- i = BIO_read(in, (char *)(file_read_buf + total_read), BUFSIZE);
- if (i < 0) {
+ bytes_read = BIO_read(in, (char *)(file_read_buf + total_read), BUFSIZE);
+ if (bytes_read < 0) {
BIO_printf(bio_err, "Read error in %s\n", argv[0]);
goto end;
}
- if (i == 0)
+ if (bytes_read == 0)
break;
- total_read += i;
- if (i == BUFSIZE)
+ total_read += bytes_read;
+ if (bytes_read == BUFSIZE)
file_read_buf = (char *)realloc(file_read_buf, BUFSIZE + total_read);
}
-
+
/* Trim trailing newline if present */
if (file_read_buf[total_read - 1] == '\n')
file_read_buf[total_read - 1] = '\0';
--- /dev/null
+#! /usr/bin/env perl
+# Copyright 2020-2025 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (the "License"). You may not use
+# this file except in compliance with the License. You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
+use strict;
+use warnings;
+
+use OpenSSL::Test qw(:DEFAULT data_file);
+use OpenSSL::Test;
+
+setup("test_prime");
+
+plan tests => 8;
+
+my $prime_file = data_file("prime.txt");
+my $composite_file = data_file("composite.txt");
+my $long_number_file = data_file("long_number.txt");
+my $non_number_file = data_file("non_number.txt");
+my $hex_number_file = data_file("hex_number.txt");
+my $bad_format_file = data_file("bad_format.txt");
+
+ok(run(app(["openssl", "prime", "-in", $prime_file])),
+ "Run openssl prime with prime number -in file");
+
+ok(run(app(["openssl", "prime", "-in", $composite_file])),
+ "Run openssl prime with composite number -in file");
+
+ok(run(app(["openssl", "prime", "-in", $long_number_file])),
+ "Run openssl prime with long number -in file");
+
+ok(!run(app(["openssl", "prime", "-in", $non_number_file])),
+ "Run openssl prime with non number -in file");
+
+ok(run(app(["openssl", "prime", "-in", "-hex", $hex_number_file])),
+ "Run openssl prime with hex number -in file");
+
+ok(!run(app(["openssl", "prime", "-in", $bad_format_file])),
+ "Run openssl prime with bad format -in file");
+
+ok(run(app(["openssl", "prime", "-in", $prime_file, $composite_file, $long_number_file])),
+ "Run openssl prime with multiple -in files");
+
+ok(!run(app(["openssl", "prime", "-in", "does_not_exist.txt"])),
+ "Run openssl prime with -in file that does not exist");
\ No newline at end of file