[Olsr-dev] freebsd fixes for src/bsd/net.c
Gianni Costanzi
(spam-protected)
Fri Sep 7 10:16:29 CEST 2007
Sorry for the empty email that I've sent before this one :(
I just wanted to say that in my opinion, it is more correct to say
strncpy(dest, src, sizeof(src))
if you want to copy the data pointed by src to the location pointed by
dest.. You wanto to copy src, and so you give the size of src (you
must already be sure that dest points to a buffer large enough to hold
src data)..
"If the destination string of a strcpy() is not large enough (that is,
if the programmer was stupid or lazy, and failed to check the size
before copying) then anything might happen. Overflowing fixed length
strings is a favorite cracker technique." - BUGS section of
"man strncpy" :)
But this is just my opinion... furthermore, I almost always use
sizeof(struct my_struct) if src is a pointer to a "struct my_struct"
data structure.
On 9/7/07, John Hay <(spam-protected)> wrote:
> Hi,
>
> The first part fix the broken use of sizeof() and the second part change
> the wireless interface detection to use the ieee80211 apis. The old
> wavelan apis has been removed from FreeBSD-current and so the upcoming
> version 7 will not have it. It should still work on 6.x too.
>
> John
> --
> John Hay -- (spam-protected) / (spam-protected)
>
>
> --- src/bsd/net.c.orig 2007-05-02 09:41:20.000000000 +0200
> +++ src/bsd/net.c 2007-08-21 21:01:57.000000000 +0200
> @@ -71,8 +71,6 @@
> #ifndef FBSD_NO_80211
> #include <net80211/ieee80211.h>
> #include <net80211/ieee80211_ioctl.h>
> -#include <dev/wi/if_wavelan_ieee.h>
> -#include <dev/wi/if_wireg.h>
> #endif
> #endif
>
> @@ -557,7 +555,7 @@
> sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr;
> if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
> continue;
> - strncpy(ifr6.ifr_name, ifname, sizeof(ifname));
> + strncpy(ifr6.ifr_name, ifname, sizeof(ifr6.ifr_name));
> if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
> {
> OLSR_PRINTF(3, "socket(AF_INET6,SOCK_DGRAM)");
> @@ -826,19 +824,17 @@
> check_wireless_interface(char *ifname)
> {
> #if defined __FreeBSD__ && !defined FBSD_NO_80211
> - struct wi_req wreq;
> - struct ifreq ifr;
> + /* From FreeBSD ifconfig/ifieee80211.c ieee80211_status() */
> + struct ieee80211req ireq;
> + u_int8_t data[32];
> +
> + memset(&ireq, 0, sizeof(ireq));
> + strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name));
> + ireq.i_data = &data;
> + ireq.i_type = IEEE80211_IOC_SSID;
> + ireq.i_val = -1;
>
> - memset((char *)&wreq, 0, sizeof(wreq));
> - memset((char *)&ifr, 0, sizeof(ifr));
> -
> - wreq.wi_len = WI_MAX_DATALEN;
> - wreq.wi_type = WI_RID_IFACE_STATS;
> -
> - strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
> - ifr.ifr_data = (caddr_t)&wreq;
> -
> - return (ioctl(olsr_cnf->ioctl_s, SIOCGWAVELAN, &ifr) >= 0) ? 1 : 0;
> + return (ioctl(olsr_cnf->ioctl_s, SIOCG80211, &ireq) >= 0) ? 1 : 0;
> #else
> return 0;
> #endif
>
> --
> Olsr-dev mailing list
> (spam-protected)
> http://lists.olsr.org/mailman/listinfo/olsr-dev
>
--
--------------------------------------------------------------------------------------------------------------
| Gianni Costanzi ((spam-protected))
| (http://utenti.lycos.it/giannicostanzi/)
|
| Gentoo Documentation Project (GDP) Member - Italian Translator
| (http://www.gentoo.org/proj/en/gdp/)
|
| Free Software Foundation Member #3844 (www.fsf.org)
| "Free Software is a matter of Liberty not price"
|
| Sun Valley in Rock Staff Member (www.sunvalleyinrock.net/forum)
--------------------------------------------------------------------------------------------------------------
More information about the Olsr-dev
mailing list