wmifs: Prevent crash when too many devices.

Patch by Chris Hanson <cph@martigny.ai.mit.edu>.  First appeared in Debian
package 1.3b1-6.

From https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=39922:
wmifs crashes with a cryptic X error message when there are more than
4 net devices.  This occurs for me because I install vmware, which
installs 4 network devices for its bridging hack.

The bug is a loop that fills a fixed-length array, but doesn't stop
when the array is full.  The fix is to add a conditional break to the
loop.  A patch appears below.

I made two additional changes: (1) increased the size of the array,
and (2) changed a name comparison to compare all of the characters of
the name, rather than just the visible characters, since there may be
multiple net devices with the same first 4 characters (vmware does
this, too).
This commit is contained in:
Doug Torrance 2014-10-22 16:34:32 -05:00 committed by Carlos R. Mafra
parent c2155050c7
commit 68555562b4

View file

@ -306,7 +306,7 @@ int main(int argc, char *argv[]) {
|* wmifs_routine *| |* wmifs_routine *|
\*******************************************************************************/ \*******************************************************************************/
#define MAX_STAT_DEVICES 4 #define MAX_STAT_DEVICES 16
typedef struct { typedef struct {
@ -485,7 +485,7 @@ void wmifs_routine(int argc, char **argv) {
stat_online = checknetdevs(); stat_online = checknetdevs();
stat_current = 0; stat_current = 0;
for (i=0; i<stat_online; i++) { for (i=0; i<stat_online; i++) {
if (!strncmp(temp, stat_devices[i].name, 4)) { if (!strcmp(temp, stat_devices[i].name)) {
stat_current = i; stat_current = i;
} }
} }
@ -718,6 +718,8 @@ int checknetdevs(void) {
strcpy(foundbuffer[devsfound], p); strcpy(foundbuffer[devsfound], p);
devsfound++; devsfound++;
} }
if (devsfound >= MAX_STAT_DEVICES)
break;
} }
fclose(fd); fclose(fd);
} }
@ -739,7 +741,7 @@ int checknetdevs(void) {
} }
} }
for (i=0, j=0; j<MAX_STAT_DEVICES; i++) { for (i=0, j=0; j<MAX_STAT_DEVICES; i++, j++) {
while (!stat_devices[j].name[0] && j < MAX_STAT_DEVICES) while (!stat_devices[j].name[0] && j < MAX_STAT_DEVICES)
j++; j++;
@ -747,8 +749,6 @@ int checknetdevs(void) {
if (j < MAX_STAT_DEVICES && i != j) { if (j < MAX_STAT_DEVICES && i != j) {
stat_devices[i] = stat_devices[j]; stat_devices[i] = stat_devices[j];
} }
j++;
} }
i--; i--;