Fixed an undersized memory allocation, causing heap corruption :-(
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3269 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -27,7 +27,6 @@ enum {
|
|||||||
typedef struct ethernet_interface {
|
typedef struct ethernet_interface {
|
||||||
ifnet_t ifnet;
|
ifnet_t ifnet;
|
||||||
int fd;
|
int fd;
|
||||||
int mtu;
|
|
||||||
} ethernet_interface;
|
} ethernet_interface;
|
||||||
|
|
||||||
#define ETHER_ADDR_LEN 6 /* Ethernet address length */
|
#define ETHER_ADDR_LEN 6 /* Ethernet address length */
|
||||||
@@ -44,7 +43,6 @@ typedef struct ether_addr {
|
|||||||
uint8 byte[ETHER_ADDR_LEN];
|
uint8 byte[ETHER_ADDR_LEN];
|
||||||
} ether_addr_t;
|
} ether_addr_t;
|
||||||
|
|
||||||
|
|
||||||
status_t lookup_devices(char *root, void *cookie);
|
status_t lookup_devices(char *root, void *cookie);
|
||||||
status_t std_ops(int32 op, ...);
|
status_t std_ops(int32 op, ...);
|
||||||
|
|
||||||
@@ -89,7 +87,6 @@ status_t send(ifnet_t *iface, net_data *data)
|
|||||||
if (!data)
|
if (!data)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +97,7 @@ status_t receive(ifnet_t *iface, net_data **data)
|
|||||||
net_data *nd;
|
net_data *nd;
|
||||||
void *frame;
|
void *frame;
|
||||||
size_t len;
|
size_t len;
|
||||||
status_t status;
|
ssize_t sz;
|
||||||
|
|
||||||
len = iface->if_mtu;
|
len = iface->if_mtu;
|
||||||
frame = malloc(len);
|
frame = malloc(len);
|
||||||
@@ -113,16 +110,16 @@ status_t receive(ifnet_t *iface, net_data **data)
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
};
|
};
|
||||||
|
|
||||||
status = read(ei->fd, frame, len);
|
sz = read(ei->fd, frame, len);
|
||||||
if (status >= B_OK) {
|
if (sz >= B_OK) {
|
||||||
g_stack->append_data(nd, frame, status, free);
|
g_stack->append_data(nd, frame, sz, (data_node_free_func) free);
|
||||||
*data = nd;
|
*data = nd;
|
||||||
return status;
|
return sz;
|
||||||
};
|
};
|
||||||
|
|
||||||
free(frame);
|
free(frame);
|
||||||
g_stack->delete_data(nd, false);
|
g_stack->delete_data(nd, false);
|
||||||
return status;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t control(ifnet_t *iface, int opcode, void *arg) { return -1; }
|
status_t control(ifnet_t *iface, int opcode, void *arg) { return -1; }
|
||||||
@@ -222,11 +219,13 @@ status_t lookup_devices(char *root, void *cookie)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
iface = (ifnet_t *) malloc(sizeof(*iface));
|
ei = (ethernet_interface *) malloc(sizeof(*ei));
|
||||||
if (!iface)
|
if (!ei)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ei = (ethernet_interface *) iface;
|
ei->fd = fd;
|
||||||
|
|
||||||
|
iface = &ei->ifnet;
|
||||||
|
|
||||||
iface->if_name = strdup(path);
|
iface->if_name = strdup(path);
|
||||||
iface->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
|
iface->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
|
||||||
@@ -234,14 +233,13 @@ status_t lookup_devices(char *root, void *cookie)
|
|||||||
iface->if_mtu = frame_size;
|
iface->if_mtu = frame_size;
|
||||||
|
|
||||||
iface->module = &nimi;
|
iface->module = &nimi;
|
||||||
ei->fd = fd;
|
|
||||||
|
|
||||||
status = g_stack->register_interface(iface);
|
status = g_stack->register_interface(iface);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user