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];


#!/bin/sh

# udhcpc script edited by Tim Riker <[email protected]>

[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

RESOLV_CONF="/etc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"

case "$1" in
        deconfig)
                /sbin/ifconfig $interface 0.0.0.0
                ;;

        renew|bound)
                /sbin/ifconfig $interface $ip $BROADCAST $NETMASK

                if [ -n "$router" ] ; then
                        echo "Deleting routers"
                        while route del default gw 0.0.0.0 dev $interface 
2>/dev/null ; do
                                :
                        done

                        for i in $router ; do
                                route add default gw $i dev $interface
                        done
                fi

                echo -n > $RESOLV_CONF
                [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
                for i in $dns ; do
                        echo adding dns $i
                        echo nameserver $i >> $RESOLV_CONF
                done

                ntpd -p $ntpsrv
                echo started npt client to $ntpsrv
                ;;
esac

exit 0
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to