@@ -159,7 +159,7 @@ static void check_file(int argn, int argc, char **argv)
159159
160160int main (int argc , char * * argv )
161161{
162- int idx , check , z , err , argn ;
162+ int idxs [ TAB_SIZE ], idx , check , y , z , err , argn ;
163163 unsigned long w , x ;
164164 unsigned char hash_buffer [MAXBLOCKSIZE ];
165165
@@ -175,16 +175,19 @@ int main(int argc, char **argv)
175175 die (EXIT_FAILURE );
176176 }
177177
178+ for (x = 0 ; x < sizeof (idxs )/sizeof (idxs [0 ]); ++ x ) {
179+ idxs [x ] = -2 ;
180+ }
178181 argn = 1 ;
179182 check = 0 ;
180- idx = -2 ;
183+ idx = 0 ;
181184
182185 while (argn < argc ){
183186 if (strcmp ("-a" , argv [argn ]) == 0 ) {
184187 argn ++ ;
185188 if (argn < argc ) {
186- idx = find_hash (argv [argn ]);
187- if (idx == -1 ) {
189+ idxs [ idx ] = find_hash (argv [argn ]);
190+ if (idxs [ idx ] == -1 ) {
188191 struct {
189192 const char * is ;
190193 const char * should ;
@@ -215,15 +218,20 @@ int main(int argc, char **argv)
215218 };
216219 for (x = 0 ; shasum_compat [x ].is != NULL ; ++ x ) {
217220 if (XSTRCMP (shasum_compat [x ].is , argv [argn ]) == 0 ) {
218- idx = find_hash (shasum_compat [x ].should );
221+ idxs [ idx ] = find_hash (shasum_compat [x ].should );
219222 break ;
220223 }
221224 }
222225 }
223- if (idx == -1 ) {
226+ if (idxs [ idx ] == -1 ) {
224227 fprintf (stderr , "%s: Unrecognized algorithm\n" , hashsum );
225228 die (EXIT_FAILURE );
226229 }
230+ idx ++ ;
231+ if ((size_t )idx >= sizeof (idxs )/sizeof (idxs [0 ])) {
232+ fprintf (stderr , "%s: Too many '-a' options chosen\n" , hashsum );
233+ die (EXIT_FAILURE );
234+ }
227235 argn ++ ;
228236 continue ;
229237 }
@@ -245,7 +253,7 @@ int main(int argc, char **argv)
245253
246254 if (argc == argn ) {
247255 w = sizeof (hash_buffer );
248- if ((err = hash_filehandle (idx , stdin , hash_buffer , & w )) != CRYPT_OK ) {
256+ if ((err = hash_filehandle (idxs [ 0 ] , stdin , hash_buffer , & w )) != CRYPT_OK ) {
249257 fprintf (stderr , "%s: File hash error: %s\n" , hashsum , error_to_string (err ));
250258 return EXIT_FAILURE ;
251259 } else {
@@ -255,14 +263,16 @@ int main(int argc, char **argv)
255263 printf (" *-\n" );
256264 }
257265 } else {
258- for (z = 3 ; z < argc ; z ++ ) {
259- w = sizeof (hash_buffer );
260- if ((err = hash_file (idx ,argv [z ],hash_buffer ,& w )) != CRYPT_OK ) {
261- fprintf (stderr , "%s: File hash error: %s\n" , hashsum , error_to_string (err ));
262- return EXIT_FAILURE ;
263- } else {
264- printf_hex (hash_buffer , w );
265- printf (" *%s\n" , argv [z ]);
266+ for (z = argn ; z < argc ; z ++ ) {
267+ for (y = 0 ; y < idx ; ++ y ) {
268+ w = sizeof (hash_buffer );
269+ if ((err = hash_file (idxs [y ],argv [z ],hash_buffer ,& w )) != CRYPT_OK ) {
270+ fprintf (stderr , "%s: File hash error: %s\n" , hashsum , error_to_string (err ));
271+ return EXIT_FAILURE ;
272+ } else {
273+ printf_hex (hash_buffer , w );
274+ printf (" *%s\n" , argv [z ]);
275+ }
266276 }
267277 }
268278 }
0 commit comments