Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Sat, 7 Jul 2012 09:46:12 +0400
From: Solar Designer <solar@...nwall.com>
To: john-dev@...ts.openwall.com
Subject: hccap2john fixes

Lukas, magnum -

hccap2john in 1.7.9-jumbo-6 is totally non-working because of erroneous
fread() return value check.  This was reported to us here:

http://www.opennet.ru/openforum/vsluhforumID3/85400.html#37

The attached patch fixes this issue and makes other minor changes.  The
code is still worse than I would have liked it to be (e.g., it does not
bother reporting the specific filenames in error messages, even though
it can read multiple files), but this is jumbo. ;-)

Thanks,

Alexander

--- src/hccap2john.c.orig	2012-06-29 01:30:55.750702897 +0000
+++ src/hccap2john.c	2012-07-07 05:34:51.488198259 +0000
@@ -15,6 +15,7 @@
 #ifndef _MSC_VER
 #include <unistd.h>
 #endif
+#include <errno.h>
 #include <assert.h>
 #include "common.h"
 
@@ -32,7 +33,7 @@ typedef struct
   unsigned char keymic[16];
 } hccap_t;
 
-void code_block(unsigned char *in, unsigned char b)
+static void code_block(unsigned char *in, unsigned char b)
 {
 	putchar(itoa64[in[0] >> 2]);
 	putchar(itoa64[((in[0] & 0x03) << 4) | (in[1] >> 4)]);
@@ -43,7 +44,7 @@ void code_block(unsigned char *in, unsig
 		putchar(itoa64[((in[1] & 0x0f) << 2)]);
 }
 
-void print_hccap(hccap_t * cap)
+static void print_hccap(hccap_t * cap)
 {
 	int i;
 	unsigned char *w = (unsigned char *) cap;
@@ -54,38 +55,47 @@ void print_hccap(hccap_t * cap)
 	puts("");
 }
 
-void process_file(const char *filename)
+static void process_file(const char *filename)
 {
 	hccap_t hccap;
 	FILE *f;
 	struct stat sb;
-	size_t bytes;
 
-	memset(&hccap, '0', sizeof(hccap_t));
 	f = fopen(filename, "r");
 	if (stat(filename, &sb) == -1) {
-		perror("stat() error");
+		perror("stat");
 		exit(EXIT_FAILURE);
 	}
-	if (sb.st_size != sizeof(hccap_t)) {
-		perror("file %s has wrong size");
+	if (sb.st_size != sizeof(hccap)) {
+		puts("file has wrong size");
+		exit(EXIT_FAILURE);
+	}
+	errno = 0;
+	if (fread(&hccap, sizeof(hccap), 1, f) != 1) {
+		if (ferror(f) && errno)
+			perror("fread");
+		else
+			puts("file read error");
 		exit(EXIT_FAILURE);
 	}
-	bytes = fread(&hccap, sizeof(hccap_t), 1, f);
-	assert(bytes==HCCAP_SIZE);
-	print_hccap(&hccap);
 	fclose(f);
+
+	print_hccap(&hccap);
 }
 
 int hccap2john(int argc, char **argv)
 {
 	int i;
+
 	assert(sizeof(hccap_t) == HCCAP_SIZE);
+
 	if (argc < 2) {
-		fprintf(stderr, "Usage: hccap2john [RACF binary files]\n");
-		return -1;
+		fprintf(stderr, "Usage: hccap2john [hccap format binary files]\n");
+		return 1;
 	}
+
 	for (i = 1; i < argc; i++)
 		process_file(argv[i]);
+
 	return 0;
 }

Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ