summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-04 10:31:26 (UTC)
committer mickeyl <mickeyl>2003-04-04 10:31:26 (UTC)
commit089385bb8ab768fbf6f394f326e565e3589163fc (patch) (side-by-side diff)
tree23891b81b11310186c43179612531bc92e52ae65
parent7da7e9cbfb52988ce801310f66b1336e0809db28 (diff)
downloadopie-089385bb8ab768fbf6f394f326e565e3589163fc.zip
opie-089385bb8ab768fbf6f394f326e565e3589163fc.tar.gz
opie-089385bb8ab768fbf6f394f326e565e3589163fc.tar.bz2
low-level network programming is sick. some wlan-drivers don't honor struct sizes
and simply write bytes _after_ the struct... this patch makes calling SIOCGIWRANGE more failure-proof.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetutils.cpp1
-rw-r--r--libopie2/opienet/onetwork.cpp57
-rw-r--r--libopie2/opienet/onetwork.h19
3 files changed, 47 insertions, 30 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index fd8f9e9..b317810 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -185 +185,2 @@ void dumpBytes( const unsigned char* data, int num )
}
+
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 66fa215..789e8ca 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -130,4 +130,4 @@ bool ONetwork::isWirelessInterface( const char* name ) const
int sfd = socket( AF_INET, SOCK_STREAM, 0 );
- iwreqstruct iwr;
- memset( &iwr, 0, sizeof( iwreqstruct ) );
+ struct iwreq iwr;
+ memset( &iwr, 0, sizeof( struct iwreq ) );
strcpy( (char*) &iwr.ifr_name, name );
@@ -154,3 +154,3 @@ ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
-ifreqstruct& ONetworkInterface::ifr() const
+struct ifreq& ONetworkInterface::ifr() const
{
@@ -174,3 +174,3 @@ void ONetworkInterface::init()
-bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const
+bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
{
@@ -379,3 +379,3 @@ OWirelessNetworkInterface::~OWirelessNetworkInterface()
-iwreqstruct& OWirelessNetworkInterface::iwr() const
+struct iwreq& OWirelessNetworkInterface::iwr() const
{
@@ -419,5 +419,2 @@ void OWirelessNetworkInterface::buildChannelList()
{
- // IEEE802.11(b) radio frequency channels
- struct iw_range range;
-
//ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
@@ -427,8 +424,17 @@ void OWirelessNetworkInterface::buildChannelList()
//ML: _too much_ space. This is damn shitty crap *sigh*
-
- _iwr.u.data.pointer = (char*) &range;
- _iwr.u.data.length = IW_MAX_FREQUENCIES; //sizeof range;
- _iwr.u.data.flags = 0;
-
- if ( !wioctl( SIOCGIWRANGE ) )
+ //ML: We allocate a large memory region in RAM and check whether the
+ //ML: driver pollutes this extra space. The complaint will be made on stdout,
+ //ML: so please forward this...
+
+ struct iwreq wrq;
+ int len = sizeof( struct iw_range )*2;
+ char *buffer = (char*) malloc( len );
+ //FIXME: Validate if we actually got the memory block
+ memset( buffer, 0, len );
+ memcpy( wrq.ifr_name, name(), IFNAMSIZ);
+ wrq.u.data.pointer = (caddr_t) buffer;
+ wrq.u.data.length = sizeof( struct iw_range );
+ wrq.u.data.flags = 0;
+
+ if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
{
@@ -449,2 +455,17 @@ void OWirelessNetworkInterface::buildChannelList()
{
+ // <check if the driver overwrites stuff>
+ int max = 0;
+ for ( int r = sizeof( struct iw_range ); r < len; r++ )
+ if (buffer[r] != 0)
+ max = r;
+ if (max > 0)
+ {
+ qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'"
+ "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
+ }
+ // </check if the driver overwrites stuff>
+
+ struct iw_range range;
+ memcpy( &range, buffer, sizeof range );
+
qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency );
@@ -456,3 +477,5 @@ void OWirelessNetworkInterface::buildChannelList()
}
+
qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." );
+ free(buffer);
}
@@ -507,3 +530,3 @@ void OWirelessNetworkInterface::setChannel( int c ) const
{
- memset( &_iwr, 0, sizeof( iwreqstruct ) );
+ memset( &_iwr, 0, sizeof( struct iwreq ) );
_iwr.u.freq.m = c;
@@ -641,3 +664,3 @@ void OWirelessNetworkInterface::setSSID( const QString& ssid )
-bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const
+bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
{
@@ -677,3 +700,3 @@ void OMonitoringInterface::setChannel( int c )
// use standard WE channel switching protocol
- memset( &_if->_iwr, 0, sizeof( iwreqstruct ) );
+ memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
_if->_iwr.u.freq.m = c;
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 7c70873..509c3db 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -74,9 +74,2 @@ class OMonitoringInterface;
-typedef struct ifreq ifreqstruct;
-typedef struct iwreq iwreqstruct;
-typedef struct iw_event iweventstruct;
-typedef struct iw_freq iwfreqstruct;
-typedef struct iw_priv_args iwprivargsstruct;
-typedef struct iw_range iwrangestruct;
-
/*======================================================================================
@@ -138,3 +131,3 @@ class ONetworkInterface : public QObject
const int _sfd;
- mutable ifreqstruct _ifr;
+ mutable ifreq _ifr;
OMonitoringInterface* _mon;
@@ -142,6 +135,6 @@ class ONetworkInterface : public QObject
protected:
- ifreqstruct& ifr() const;
+ struct ifreq& ifr() const;
virtual void init();
bool ioctl( int call ) const;
- bool ioctl( int call, ifreqstruct& ) const;
+ bool ioctl( int call, struct ifreq& ) const;
};
@@ -224,8 +217,8 @@ class OWirelessNetworkInterface : public ONetworkInterface
virtual void init();
- iwreqstruct& iwr() const;
+ struct iwreq& iwr() const;
bool wioctl( int call ) const;
- bool wioctl( int call, iwreqstruct& ) const;
+ bool wioctl( int call, struct iwreq& ) const;
protected:
- mutable iwreqstruct _iwr;
+ mutable struct iwreq _iwr;
QMap<int,int> _channels;