I don't know how it is possible for /dev/hwrng to be present but
unreadable.  Loading rng-core on a system without a hardware random
driver doesn't do it.  However, it is possible to reproduce this poor
randomisation after running 'ln -s null /dev/hwrng'.

I've uploaded a fix for this and am attaching the NMU diff.

Ben.

-- 
Ben Hutchings
Lowery's Law:
             If it jams, force it. If it breaks, it needed replacing anyway.
diff -Nru macchanger-1.7.0/debian/changelog macchanger-1.7.0/debian/changelog
--- macchanger-1.7.0/debian/changelog	2014-12-18 11:51:19.000000000 +0000
+++ macchanger-1.7.0/debian/changelog	2015-01-16 23:22:14.000000000 +0000
@@ -1,3 +1,10 @@
+macchanger (1.7.0-5.1) unstable; urgency=medium
+
+  * Non-maintainer upload
+  * Check for random device read errors (Closes: #775005)
+
+ -- Ben Hutchings <b...@decadent.org.uk>  Fri, 16 Jan 2015 23:22:13 +0000
+
 macchanger (1.7.0-5) unstable; urgency=low
 
   * fix maintainer-script-without-set-e config
diff -Nru macchanger-1.7.0/debian/patches/check-random-device-read-errors.patch macchanger-1.7.0/debian/patches/check-random-device-read-errors.patch
--- macchanger-1.7.0/debian/patches/check-random-device-read-errors.patch	1970-01-01 01:00:00.000000000 +0100
+++ macchanger-1.7.0/debian/patches/check-random-device-read-errors.patch	2015-01-16 23:03:34.000000000 +0000
@@ -0,0 +1,47 @@
+Description: Check for random device read errors
+ In some cases it is possible to open /dev/hwrng but not to read from it.
+ We need to check for errors and move on to the next possible random device
+ in this case.
+Author: Ben Hutchings <b...@decadent.org.uk>
+Bug-Debian: https://bugs.debian.org/775005
+
+---
+--- a/src/main.c
++++ b/src/main.c
+@@ -91,17 +91,29 @@ print_mac (const char *s, const mac_t *m
+ static void
+ random_seed (void)
+ {
++	static const char *const dev_names[] = {
++		"/dev/hwrng",
++		"/dev/random",
++		"/dev/urandom",
++		NULL,
++	};
+ 	int            fd;
+ 	struct timeval tv;
+ 	unsigned int   seed;
++	const char *const *name;
++	ssize_t        read_len = 0;
+ 
+-	if ((fd = open("/dev/hwrng", O_RDONLY)) >= 0 ||
+-	    (fd = open("/dev/random", O_RDONLY)) >= 0 ||
+-	    (fd = open("/dev/urandom", O_RDONLY)) >= 0)
+-	{
+-		read (fd, &seed, sizeof(seed));
+-		close (fd);
+-	} else {
++	for (name = dev_names; *name; name++) {
++		fd = open(*name, O_RDONLY);
++		if (fd >= 0) {
++			read_len = read (fd, &seed, sizeof(seed));
++			close (fd);
++			if (read_len == sizeof(seed))
++				break;
++		}
++	}
++
++	if (read_len != sizeof(seed)) {
+ 		gettimeofday (&tv, NULL);
+ 		seed = (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec;
+ 	}
diff -Nru macchanger-1.7.0/debian/patches/series macchanger-1.7.0/debian/patches/series
--- macchanger-1.7.0/debian/patches/series	2014-03-18 14:59:20.000000000 +0000
+++ macchanger-1.7.0/debian/patches/series	2015-01-16 22:51:05.000000000 +0000
@@ -1,3 +1,4 @@
 02-fix_usage_message.patch
 06-update_OUI_list.patch
 08-fix_random_MAC_choice.patch
+check-random-device-read-errors.patch

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to