@@ -12,6 +12,7 @@ extern "C" {
1212#include "acquire_common_defs.h"
1313#include "acquire_handle.h"
1414#include "libacquire_export.h"
15+ #include <acquire_string_extras.h>
1516
1617struct rhash_backend {
1718 rhash handle ;
@@ -98,12 +99,15 @@ int _librhash_verify_async_start(struct acquire_handle *handle,
9899 "rhash backend allocation failed" );
99100 return -1 ;
100101 } /* LCOV_EXCL_STOP */
101- be -> file = fopen (filepath , "rb" );
102- if (!be -> file ) {
103- acquire_handle_set_error (handle , ACQUIRE_ERROR_FILE_OPEN_FAILED , "%s" ,
104- strerror (errno ));
105- free (be );
106- return -1 ;
102+ {
103+ const errno_t err = fopen_s (& be -> file , filepath , "rb" );
104+ if (err != 0 || be -> file == NULL ) {
105+ fprintf (stderr , "couldn't open file for reading %s\n" , filepath );
106+ acquire_handle_set_error (handle , ACQUIRE_ERROR_FILE_OPEN_FAILED ,
107+ "Cannot open file: %s" , filepath );
108+ free (be );
109+ return -1 ;
110+ }
107111 }
108112 be -> handle = rhash_init (rhash_algo_id );
109113 if (!be -> handle ) { /* LCOV_EXCL_START */
@@ -113,7 +117,17 @@ int _librhash_verify_async_start(struct acquire_handle *handle,
113117 return -1 ;
114118 } /* LCOV_EXCL_STOP */
115119 be -> algorithm_id = rhash_algo_id ;
120+ #if defined(_MSC_VER ) && !defined(__INTEL_COMPILER ) || \
121+ defined(__STDC_LIB_EXT1__ ) && __STDC_WANT_LIB_EXT1__
122+ {
123+ const errno_t e = strncpy_s (be -> expected_hash , sizeof (be -> expected_hash ),
124+ expected_hash , sizeof (be -> expected_hash ) - 1 );
125+ if (e )
126+ be -> expected_hash [0 ] = '\0' ;
127+ }
128+ #else
116129 strncpy (be -> expected_hash , expected_hash , sizeof (be -> expected_hash ) - 1 );
130+ #endif
117131 handle -> backend_handle = be ;
118132 handle -> status = ACQUIRE_IN_PROGRESS ;
119133 return 0 ;
@@ -146,13 +160,21 @@ enum acquire_status _librhash_verify_async_poll(struct acquire_handle *handle) {
146160 acquire_handle_set_error (handle , ACQUIRE_ERROR_UNKNOWN ,
147161 "rhash_update failed" );
148162 } else { /* LCOV_EXCL_STOP */
149- handle -> bytes_processed += bytes_read ;
163+ handle -> bytes_processed += ( off_t ) bytes_read ;
150164 return ACQUIRE_IN_PROGRESS ;
151165 }
152166 }
153167 if (ferror (be -> file )) { /* LCOV_EXCL_START */
154- acquire_handle_set_error (handle , ACQUIRE_ERROR_FILE_READ_FAILED , "%s" ,
155- strerror (errno ));
168+ #if defined(_MSC_VER ) && !defined(__INTEL_COMPILER ) || \
169+ defined(__STDC_LIB_EXT1__ ) && __STDC_WANT_LIB_EXT1__
170+ char error_code [256 ];
171+ strerror_s (error_code , sizeof (error_code ), errno );
172+ acquire_handle_set_error (handle , ACQUIRE_ERROR_FILE_READ_FAILED ,
173+ "File read error: %s" , error_code );
174+ #else
175+ acquire_handle_set_error (handle , ACQUIRE_ERROR_FILE_READ_FAILED ,
176+ "File read error: %s" , strerror (errno ));
177+ #endif
156178 } else { /* LCOV_EXCL_STOP */
157179 unsigned char hash [64 ];
158180 char computed_hex [130 ];
0 commit comments