From a5fb71e8bf8307710d39b074031729785e9f4cb1 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Tue, 17 Jan 2012 01:41:18 -0700 Subject: [PATCH] Bug 3449: pt3: shm_open can fail with a mangled path --- src/ipc/mem/Segment.cc | 10 ++++++++-- src/tests/testRock.cc | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ipc/mem/Segment.cc b/src/ipc/mem/Segment.cc index 832261338c..b9cfa6b2f3 100644 --- a/src/ipc/mem/Segment.cc +++ b/src/ipc/mem/Segment.cc @@ -178,9 +178,15 @@ Ipc::Mem::Segment::statSize(const char *context) const String Ipc::Mem::Segment::GenerateName(const char *id) { - assert(BasePath); + assert(BasePath && *BasePath); static const bool nameIsPath = shm_portable_segment_name_is_path(); - String name(nameIsPath ? BasePath : "/squid-"); + String name; + if (nameIsPath) { + name.append(BasePath); + if (name[name.size()-1] != '/') + name.append('/'); + } else + name.append("/squid-"); // append id, replacing slashes with dots for (const char *slash = strchr(id, '/'); slash; slash = strchr(id, '/')) { diff --git a/src/tests/testRock.cc b/src/tests/testRock.cc index 600fe828dc..1b604c4e07 100644 --- a/src/tests/testRock.cc +++ b/src/tests/testRock.cc @@ -41,7 +41,7 @@ testRock::setUp() throw std::runtime_error("Failed to clean test work directory"); // use current directory for shared segments (on path-based OSes) - Ipc::Mem::Segment::BasePath = ""; + Ipc::Mem::Segment::BasePath = "."; Store::Root(new StoreController); -- 2.47.2