[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] Small Fix in mac-802_11 for easier debugging...



Hi ns developers,

when using the mac-802_11 features of ns (2.1b6 or b7-current), I had
several strange core dumps where the value of different variables
changed although the program code did not contain any (obvious)
changes of the variables.

The problem was in my case in max-802_11.cc, line 1472 pp:

-------------------------------------
	if(dst != MAC_BROADCAST) {
		Host *h = &cache_[src];

		if(h->seqno && h->seqno == dh->dh_scontrol) {
			discard(p, DROP_MAC_DUPLICATE);
			return;
		}
		h->seqno = dh->dh_scontrol;
	}
------------------
The variable src had sometimes a higher value than the array size and
writing to h->seqno caused the changing variable values (with
especially strange effects since cache_ is the last variable in class
Mac802_11 so that writing over the end of the array could change any
arbitrary variable in the memory behind the mac802_11 class
instance...)

In order to make life for debugging a little easier, I propose to
change the code to something like:

-------------------------------------
	if(dst != MAC_BROADCAST) {
		if (src < (u_int32_t) cache_node_count_) {
			Host *h = &cache_[src];

			if(h->seqno && h->seqno == dh->dh_scontrol) {
				discard(p, DROP_MAC_DUPLICATE);
				return;
			}
			h->seqno = dh->dh_scontrol;
		} else printf ("MAC_802_11: accessing MAC cache_ array out of range (src %u dst %u!\n", src, dst);
	}
--------------------------------------

And probably it would be nice to check if there are more such
possibilities of writing over the end of an array in ns where an
additional 'if' would make debugging much easier.

BTW: My problem was caused by the fact that I gave a too small value
as parameter to 'create-god' (forgot to add to base station nodes)...


Best regards,

/J"org

----
J"org Diederich
Institute of Operating Systems and Computer Networks, 
Technical University Braunschweig, Germany
Email: [email protected]