Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic actually check the return value from m_gethdr() a...
details: https://anonhg.NetBSD.org/src/rev/3e48aac76805
branches: trunk
changeset: 338863:3e48aac76805
user: macallan <macallan%NetBSD.org@localhost>
date: Fri Jun 12 17:24:02 2015 +0000
description:
actually check the return value from m_gethdr() and deal with errors
now we no longer segfault in dme_allocate_buffer()
diffstat:
sys/dev/ic/dm9000.c | 36 +++++++++++++++++++++++++++++++++---
1 files changed, 33 insertions(+), 3 deletions(-)
diffs (71 lines):
diff -r 1c7486d1ef7c -r 3e48aac76805 sys/dev/ic/dm9000.c
--- a/sys/dev/ic/dm9000.c Fri Jun 12 17:02:30 2015 +0000
+++ b/sys/dev/ic/dm9000.c Fri Jun 12 17:24:02 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm9000.c,v 1.7 2015/03/14 13:45:43 macallan Exp $ */
+/* $NetBSD: dm9000.c,v 1.8 2015/06/12 17:24:02 macallan Exp $ */
/*
* Copyright (c) 2009 Paul Fleischer
@@ -809,8 +809,12 @@
sc->dme_io, DM9000_MRCMD);
rx_status = sc->sc_pkt_read(sc, ifp, &m);
-
- if (rx_status & (DM9000_RSR_CE | DM9000_RSR_PLE)) {
+ if (m == NULL) {
+ /* failed to allocate a receive buffer */
+ ifp->if_ierrors++;
+ RX_DPRINTF(("dme_receive: "
+ "Error allocating buffer\n"));
+ } else if (rx_status & (DM9000_RSR_CE | DM9000_RSR_PLE)) {
/* Error while receiving the packet,
* discard it and keep track of counters
*/
@@ -1082,6 +1086,18 @@
m = dme_alloc_receive_buffer(ifp, frame_length);
+ if (m == NULL) {
+ /*
+ * didn't get a receive buffer, so we read the rest of the
+ * packet, throw it away and return an error
+ */
+ for (i = 0; i < frame_length; i += 2 ) {
+ data = bus_space_read_2(sc->sc_iot,
+ sc->sc_ioh, sc->dme_data);
+ }
+ *outBuf = NULL;
+ return 0;
+ }
buf = mtod(m, uint16_t*);
@@ -1163,6 +1179,18 @@
m = dme_alloc_receive_buffer(ifp, frame_length);
+ if (m == NULL) {
+ /*
+ * didn't get a receive buffer, so we read the rest of the
+ * packet, throw it away and return an error
+ */
+ for (i = 0; i < frame_length; i++ ) {
+ data = bus_space_read_2(sc->sc_iot,
+ sc->sc_ioh, sc->dme_data);
+ }
+ *outBuf = NULL;
+ return 0;
+ }
buf = mtod(m, uint8_t *);
@@ -1190,6 +1218,8 @@
int pad;
MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (m == NULL) return NULL;
+
m->m_pkthdr.rcvif = ifp;
/* Ensure that we always allocate an even number of
* bytes in order to avoid writing beyond the buffer
Home |
Main Index |
Thread Index |
Old Index