Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 0778169c613c655cac3f77c206d2ad44 > files > 3

macchanger-1.5.0-9.fc14.src.rpm

Fix computation of mac list lengths - in some places, code assumed static list
(computing length as sizeof(list)/sizeof(item)), while dynamic memory
allocation is used now.

diff -pruN macchanger-1.5.0.orig/src/maclist.c macchanger-1.5.0/src/maclist.c
--- macchanger-1.5.0.orig/src/maclist.c	2002-12-03 18:52:48.000000000 +0100
+++ macchanger-1.5.0/src/maclist.c	2009-09-02 20:20:10.000000000 +0200
@@ -32,6 +32,9 @@
 card_mac_list_item_t *list_others   = NULL; /* IEEE OUI */
 card_mac_list_item_t *list_wireless = NULL; /* Wireless cards */
 
+int list_others_len   = 0;
+int list_wireless_len = 0;
+
 
 static char *
 mc_maclist_get_cardname_from_list (const mac_t *mac, card_mac_list_item_t *list)
@@ -76,12 +79,9 @@ mc_maclist_get_cardname_with_default (co
 }
 
 static void
-mc_maclist_set_random_vendor_from_list (mac_t *mac, card_mac_list_item_t *list)
+mc_maclist_set_random_vendor_from_list (mac_t *mac, card_mac_list_item_t *list, int list_len)
 {
-	   int i, num = 0;
-
-	   /* Count */
-	   while (list[++num].name);
+	   int i, num = list_len;
 
 	   /* Choose one randomly */
 	   num = random()%num;
@@ -96,25 +96,23 @@ mc_maclist_set_random_vendor_from_list (
 void
 mc_maclist_set_random_vendor (mac_t *mac, mac_type_t type)
 {
-	   int total, num;
-	   total = LIST_LENGHT (list_others) +
-		   LIST_LENGHT (list_wireless);
+	   int num;
 
-	   num = random() % total;
+	   num = random() % ( list_others_len + list_wireless_len );
 	   
 	   switch (type) {
 	   case mac_is_anykind:
-			 if (num < LIST_LENGHT(list_others)) {
-				    mc_maclist_set_random_vendor_from_list (mac, list_others);
+			 if (num < list_others_len) {
+				    mc_maclist_set_random_vendor_from_list (mac, list_others, list_others_len);
 			 } else {
-				    mc_maclist_set_random_vendor_from_list (mac, list_wireless);
+				    mc_maclist_set_random_vendor_from_list (mac, list_wireless, list_wireless_len);
 			 }
 			 break;
 	   case mac_is_wireless:
-			 mc_maclist_set_random_vendor_from_list (mac, list_wireless);
+			 mc_maclist_set_random_vendor_from_list (mac, list_wireless, list_wireless_len);
 			 break;
 	   case mac_is_others:
-			 mc_maclist_set_random_vendor_from_list (mac, list_others);
+			 mc_maclist_set_random_vendor_from_list (mac, list_others, list_others_len);
 			 break;
 	   }
 }
@@ -160,12 +158,12 @@ mc_maclist_print (const char *keyword)
 
 
 static card_mac_list_item_t *
-mc_maclist_read_from_file (const char *fullpath)
+mc_maclist_read_from_file (const char *fullpath, int *list_len)
 {
 	FILE *f;
 	char *line;
 	char  tmp[512];
-	int   num =0;
+	int   num = 0;
 	card_mac_list_item_t *list;
 
 	if ((f = fopen(fullpath, "r")) == NULL) {
@@ -199,6 +197,7 @@ mc_maclist_read_from_file (const char *f
 
 	fclose (f);
 
+	*list_len = num;
 	return list;
 }
 
@@ -206,8 +205,8 @@ mc_maclist_read_from_file (const char *f
 int
 mc_maclist_init (void)
 {
-	list_others = mc_maclist_read_from_file(LISTDIR "/OUI.list");
-	list_wireless = mc_maclist_read_from_file(LISTDIR "/wireless.list");
+	list_others = mc_maclist_read_from_file(LISTDIR "/OUI.list", &list_others_len);
+	list_wireless = mc_maclist_read_from_file(LISTDIR "/wireless.list", &list_wireless_len);
 
 	return (list_others && list_wireless)? 0 : -1;
 }
diff -pruN macchanger-1.5.0.orig/src/maclist.h macchanger-1.5.0/src/maclist.h
--- macchanger-1.5.0.orig/src/maclist.h	2002-12-03 18:52:57.000000000 +0100
+++ macchanger-1.5.0/src/maclist.h	2009-09-02 20:20:42.000000000 +0200
@@ -33,7 +33,6 @@ typedef struct {
 	unsigned char byte[3];
 } card_mac_list_item_t;
 
-#define LIST_LENGHT(l)   ((sizeof(l) / sizeof(card_mac_list_item_t))-1)
 #define CARD_NAME(x)     mc_maclist_get_cardname_with_default(x, "unknown")
 
 int    mc_maclist_init  (void);