[Etherboot-developers] Uninitialized 'iplen' in nic.c
Brought to you by:
marty_connor,
stefanhajnoczi
|
From: Robb M. <ma...@ac...> - 2003-05-02 02:18:07
|
Attached patch against etherboot-5.1.8 corrects a coding issue in
await_reply() that could (in a bizarre set of circumstances) use the
variable 'iplen' without it being initialized. I doubt this would ever occur
in practice, but....
I submit the attached patch for cleanliness.
BTW - I have commence hacking NIC.C into pieces (slicing down protocol
lines). So far, I have created:
- dhcp.c
- ip.c
- mcast.c
- rarp.c
- tftp.c
- udp.c
, and have retained the balance of (appropriate) code in 'nic.c'.
I have modified the Makefile, and have successfully rebuilt, although I have
yet to resolve a slight increase in compiled filesize. Next step is to build
a UDP test message application, then on to memtest86 & syslog.
Cheers,
Robb.
---------------------------------
*** nic_org.c Thu May 1 21:32:52 2003
--- nic.c Thu May 1 21:38:09 2003
***************
*** 1032,1037 ****
--- 1032,1038 ----
} else continue; /* what else could we do with it? */
/* Verify an IP header */
ip = 0;
+ udp = 0;
if ((ptype == IP) && (nic.packetlen >= ETH_HLEN + sizeof(struct iphdr)))
{
unsigned ipoptlen;
ip = (struct iphdr *)&nic.packet[ETH_HLEN];
***************
*** 1061,1081 ****
nic.packetlen - ipoptlen);
nic.packetlen -= ipoptlen;
}
! }
! udp = 0;
! if (ip && (ip->protocol == IP_UDP) &&
! (nic.packetlen >=
! ETH_HLEN + sizeof(struct iphdr) + sizeof(struct udphdr))) {
! udp = (struct udphdr *)&nic.packet[ETH_HLEN + sizeof(struct iphdr)];
! /* Make certain we have a reasonable packet length */
! if (ntohs(udp->len) > (ntohs(ip->len) - iplen))
! continue;
! if (udp->chksum && udpchksum(ip, udp)) {
! printf("UDP checksum error\n");
! continue;
! }
}
result = reply(ival, ptr, ptype, ip, udp);
if (result > 0) {
--- 1062,1081 ----
nic.packetlen - ipoptlen);
nic.packetlen -= ipoptlen;
}
! if ((ip->protocol == IP_UDP) &&
! (nic.packetlen >=
! ETH_HLEN + sizeof(struct iphdr) + sizeof(struct udphdr))) {
! udp = (struct udphdr *)&nic.packet[ETH_HLEN + sizeof(struct iphdr)];
! /* Make certain we have a reasonable packet length */
! if (ntohs(udp->len) > (ntohs(ip->len) - iplen))
! continue;
! if (udp->chksum && udpchksum(ip, udp)) {
! printf("UDP checksum error\n");
! continue;
! }
! }
}
result = reply(ival, ptr, ptype, ip, udp);
if (result > 0) {
---------------------------------
|