]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
diskd: avoid abort on shared memory exhaustion (#2241)
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Mon, 6 Oct 2025 13:19:05 +0000 (13:19 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 6 Oct 2025 13:19:16 +0000 (13:19 +0000)
src/DiskIO/DiskDaemon/DiskdFile.cc
src/DiskIO/DiskDaemon/DiskdIOStrategy.cc

index a30da2e96ec194515ec1a8f44fe3bb8b7021a1ec..787ea11e71ed15c6a5f1db460d011053fba1f111 100644 (file)
@@ -59,6 +59,13 @@ DiskdFile::open(int flags, mode_t, RefCount<IORequestor> 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<IORequestor> 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<char *>(aRequest->buf));
+        notifyClient();
+        ioRequestor = nullptr;
+        return;
+    }
+
     memcpy(sbuf, aRequest->buf, aRequest->len);
 
     if (aRequest->free_func)
index 7da85e17c6cbaa39389d92fb119be21aa5be15f8..af8708e2c6fcadb2b4cde8bec193a3595282476a 100644 (file)
@@ -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));