From: Joshua Rogers Date: Mon, 6 Oct 2025 13:19:05 +0000 (+0000) Subject: diskd: avoid abort on shared memory exhaustion (#2241) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bbc23aada0cde2712e0a8fdc35598650007638df;p=thirdparty%2Fsquid.git diskd: avoid abort on shared memory exhaustion (#2241) --- diff --git a/src/DiskIO/DiskDaemon/DiskdFile.cc b/src/DiskIO/DiskDaemon/DiskdFile.cc index a30da2e96e..787ea11e71 100644 --- a/src/DiskIO/DiskDaemon/DiskdFile.cc +++ b/src/DiskIO/DiskDaemon/DiskdFile.cc @@ -59,6 +59,13 @@ DiskdFile::open(int flags, mode_t, RefCount callback) mode = flags; ssize_t shm_offset; char *buf = (char *)IO->shm.get(&shm_offset); + if (!buf) { + errorOccured = true; + ioRequestor->ioCompletedNotification(); + ioRequestor = nullptr; + return; + } + xstrncpy(buf, path_, SHMBUF_BLKSZ); ioAway(); int x = IO->send(_MQD_OPEN, @@ -90,6 +97,13 @@ DiskdFile::create(int flags, mode_t, RefCount callback) mode = flags; ssize_t shm_offset; char *buf = (char *)IO->shm.get(&shm_offset); + if (!buf) { + errorOccured = true; + notifyClient(); + ioRequestor = nullptr; + return; + } + xstrncpy(buf, path_, SHMBUF_BLKSZ); ioAway(); int x = IO->send(_MQD_CREATE, @@ -120,7 +134,12 @@ DiskdFile::read(ReadRequest *aRead) assert (ioRequestor.getRaw() != nullptr); ssize_t shm_offset; char *rbuf = (char *)IO->shm.get(&shm_offset); - assert(rbuf); + if (!rbuf) { + errorOccured = true; + notifyClient(); + ioRequestor = nullptr; + return; + } ioAway(); int x = IO->send(_MQD_READ, id, @@ -281,6 +300,15 @@ DiskdFile::write(WriteRequest *aRequest) debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest->buf << ", off " << aRequest->offset << ", len " << aRequest->len); ssize_t shm_offset; char *sbuf = (char *)IO->shm.get(&shm_offset); + if (!sbuf) { + errorOccured = true; + if (aRequest->free_func) + aRequest->free_func(const_cast(aRequest->buf)); + notifyClient(); + ioRequestor = nullptr; + return; + } + memcpy(sbuf, aRequest->buf, aRequest->len); if (aRequest->free_func) diff --git a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc index 7da85e17c6..af8708e2c6 100644 --- a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc +++ b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc @@ -115,6 +115,11 @@ DiskdIOStrategy::unlinkFile(char const *path) buf = (char *)shm.get(&shm_offset); + if (!buf) { + unlinkdUnlink(path); + return; + } + xstrncpy(buf, path, SHMBUF_BLKSZ); x = send(_MQD_UNLINK, @@ -233,6 +238,11 @@ SharedMemory::get(ssize_t * shm_offset) break; } + if (!aBuf) { + debugs(79, DBG_IMPORTANT, "ERROR: out of shared-memory buffers"); + return nullptr; + } + assert(aBuf); assert(aBuf >= buf); assert(aBuf < buf + (nbufs * SHMBUF_BLKSZ));