[PATCH] dhcpc.c: fix found_opts
Lambrecht Jürgen
J.Lambrecht at TELEVIC.com
Tue Oct 11 14:19:21 UTC 2011
Hello,
The patch below fixes a bug in networking/udhcp/dhcpc.c. Here my reasoning:
There are 256 dhcp options supported, so 256 bits to store.
You want to store that in an unsigned (BITMAP define), 32b in my case.
So you need an unsigned array of 256/sizeoff(unsigned) == 8 elements. In
the code, the define BBITS is used for this, and the bug is that *8 is
added to that define, resulting in an array of only 1 element (32b) to
store 256 bits.
To set the bits, the define BMASK is used. Also here the bug is that *8
is added. Result:
unsigned found_opts[0] |= 1<<42
which is clearly wrong.
I tested this patch on a imx27pdk based board (arm9) by using the script
in attach. ('udhcpc -vv' shows a lot of debug info)(see also ltib
mailing list - therefore the CVS diff instead of git)
Kind regards,
Jürgen
diff --exclude CVS --exclude .git -uNr
busybox-1.19.2/networking/udhcp/dhcpc.c
busybox-1.19.2.modified/networking/udhcp/dhcpc.c
--- busybox-1.19.2/networking/udhcp/dhcpc.c 2011-08-22
04:57:50.000000000 +0200
+++ busybox-1.19.2.modified/networking/udhcp/dhcpc.c 2011-10-11
09:42:04.030686000 +0200
@@ -295,8 +295,8 @@
uint8_t overload = 0;
#define BITMAP unsigned
-#define BBITS (sizeof(BITMAP) * 8)
-#define BMASK(i) (1 << (i & (sizeof(BITMAP) * 8 - 1)))
+#define BBITS (sizeof(BITMAP)) /* no of bits of basic variable of array */
+#define BMASK(i) (1 << (i & (sizeof(BITMAP) - 1)))
#define FOUND_OPTS(i) (found_opts[(unsigned)i / BBITS])
BITMAP found_opts[256 / BBITS];
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dhcpc.script
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20111011/10a51f94/attachment.ksh>
More information about the busybox
mailing list