From 8c28e64bcd6aa125eb3aeacdb4a375f76f372ff7 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Wed, 30 Mar 2011 21:30:28 +0000 Subject: [PATCH] Check some of the previously unchecked error cases when loading firmware. This makes it abort earlier when no firmware files are available. Note that this worked some time ago and seems to be an edge case triggering an issue in the slab allocator. Freeing the buffer (possibly allocated with an invalid size) in the error case triggered the assert in #6679. That should probably be looked at, but meanwhile this should close #6679. Note also that looking for firmware is deliberatly done only at open() time, since the configured operational mode determines the firmware to be used and having the firmware loaded later makes the mode easily changeable at runtime. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41144 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../drivers/network/wlan/ipw2100/ipw2100.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/add-ons/kernel/drivers/network/wlan/ipw2100/ipw2100.cpp b/src/add-ons/kernel/drivers/network/wlan/ipw2100/ipw2100.cpp index bc257b374b..18596ee51b 100644 --- a/src/add-ons/kernel/drivers/network/wlan/ipw2100/ipw2100.cpp +++ b/src/add-ons/kernel/drivers/network/wlan/ipw2100/ipw2100.cpp @@ -1179,10 +1179,24 @@ IPW2100::LoadMicrocodeAndFirmware() TRACE_ALWAYS(("IPW2100: loading firmware %s\n", firmware)); int fd = open(firmware, B_READ_ONLY); + if (fd < 0) { + TRACE_ALWAYS(("IPW2100: firmware file unavailable\n")); + return B_ERROR; + } + int32 fileSize = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); + if (fileSize <= 0) { + TRACE_ALWAYS(("IPW2100: firmware file seems empty\n")); + return B_ERROR; + } uint8 *buffer = (uint8 *)malloc(fileSize); + if (buffer == NULL) { + TRACE_ALWAYS(("IPW2100: no memory for firmware buffer\n")); + return B_NO_MEMORY; + } + ssize_t readCount = read(fd, buffer, fileSize); TRACE(("IPW2100: read %ld bytes\n", readCount)); close(fd);