Skip to content

Stack smash error on Linux when using libevent #1322

@uilianries

Description

@uilianries

Hello!

Description

When building and consuming pistache 0.4.26 on Linux Ubuntu 24.04 using its GCC13, and trying to consume the produced library using a simple validation, I have a stack smash error, like:

/test_package
*** stack smashing detected ***: terminated
Aborted (core dumped)

Environment

OS: GNU/Linux 6.8.0-60-generic
Distro: Ubuntu 24.04.1 LTS
Compiler: gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
CPU Architecture: x86_64
Build Type: Release and Debug (same error on both)

Pistache version: 0.4.26 (https://github.com/pistacheio/pistache/archive/refs/tags/v0.4.26.tar.gz)
Meson version: 1.7.2
libevent version: 2.1.12
OpenSSL version: 3.5.1
rapidjson version: 1.1.0

Steps to reproduce

First, we build Pistache as usual:

wget https://github.com/pistacheio/pistache/archive/refs/tags/v0.4.26.tar.gz
tar zxf v0.4.26.tar.gz
cd pistache-0.4.26/
mkdir build && cd build/
meson setup .. -DPISTACHE_USE_SSL=true -DPISTACHE_USE_RAPIDJSON=true -DPISTACHE_FORCE_LIBEVENT=true --prefix=/tmp/pistache/install --default-library=static
meson compile
meson install

Then, we consume using a simple example:

#include "pistache/endpoint.h"

using namespace Pistache;

class HelloHandler : public Http::Handler {
public:

    HTTP_PROTOTYPE(HelloHandler)

    void onRequest(const Http::Request& request, Http::ResponseWriter response) override{
        response.send(Pistache::Http::Code::Ok, "Hello World\n");
    }
};

int main() {
    Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(9080));
    auto opts = Pistache::Http::Endpoint::options()
        .threads(1);

    Http::Endpoint server(addr);
    server.init(opts);
    server.setHandler(Http::make_handler<HelloHandler>());
    server.shutdown();

	return 0;
}

And build it as simple as possible:

g++ example.cpp -o example -std=c++17 -I/tmp/pistache/install/include /tmp/pistache/install/lib/x86_64-linux-gnu/libpistache.a -lssl -lcrypto -levent -levent_pthreads -lpthread

Details

My current build log:

Details
  • wget https://github.com/pistacheio/pistache/archive/refs/tags/v0.4.26.tar.gz
    --2025-07-23 10:32:29-- https://github.com/pistacheio/pistache/archive/refs/tags/v0.4.26.tar.gz
    Resolving github.com (github.com)... 140.82.121.4
    Connecting to github.com (github.com)|140.82.121.4|:443... connected.
    HTTP request sent, awaiting response... 302 Found
    Location: https://codeload.github.com/pistacheio/pistache/tar.gz/refs/tags/v0.4.26 [following]
    --2025-07-23 10:32:29-- https://codeload.github.com/pistacheio/pistache/tar.gz/refs/tags/v0.4.26
    Resolving codeload.github.com (codeload.github.com)... 140.82.121.9
    Connecting to codeload.github.com (codeload.github.com)|140.82.121.9|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: unspecified [application/x-gzip]
    Saving to: 'v0.4.26.tar.gz'

    0K .......... .......... .......... .......... .......... 946K
    50K .......... .......... .......... .......... .......... 2.13M
    100K .......... .......... .......... .......... .......... 22.9M
    150K .......... .......... .......... .......... .......... 2.02M
    200K .......... .......... .......... .......... .......... 17.4M
    250K .......... .......... .......... .......... .......... 19.4M
    300K .......... .......... .......... .......... .......... 6.60M
    350K .......... .......... .......... .......... .......... 3.62M
    400K .......... .......... .......... .......... .......... 15.5M
    450K .......... .......... .......... .......... .......... 30.7M
    500K .......... .......... .......... .......... .......... 31.3M
    550K .......... .......... .......... .......... .......... 32.3M
    600K .......... .......... .......... ...... 11.6M=0.1s

2025-07-23 10:32:30 (4.47 MB/s) - 'v0.4.26.tar.gz' saved [651892]

  • tar zxf v0.4.26.tar.gz
  • cd pistache-0.4.26/
  • mkdir build
  • cd build/
  • meson setup .. -DPISTACHE_USE_SSL=true -DPISTACHE_USE_RAPIDJSON=true -DPISTACHE_FORCE_LIBEVENT=true --prefix=/tmp/pistache/install --default-library=static
    The Meson build system
    Version: 1.3.2
    Source dir: /tmp/build/pistache-0.4.26
    Build dir: /tmp/build/pistache-0.4.26/build
    Build type: native build
    Project name: pistache
    Project version: 0.3.0
    C++ compiler for the host machine: c++ (gcc 13.3.0 "c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0")
    C++ linker for the host machine: c++ ld.bfd 2.42
    Host machine cpu family: x86_64
    Host machine cpu: x86_64
    Compiler for C++ supports arguments -Wconversion: YES
    Compiler for C++ supports arguments -Wno-sign-conversion: YES
    Compiler for C++ supports arguments -Wno-missing-field-initializers: YES
    Run-time dependency threads found: YES
    Checking if "C++20 std::chrono" compiles: NO
    Found pkg-config: YES (/usr/bin/pkg-config) 1.8.1
    Found CMake: /usr/bin/cmake (3.28.3)
    Run-time dependency howardhinnant-date found: NO (tried pkgconfig and cmake)
    Run-time dependency hinnant-date found: NO (tried pkgconfig and cmake)
    Run-time dependency date found: NO (tried pkgconfig and cmake)
    Looking for a fallback subproject for the dependency date

Executing subproject hinnant-date

hinnant-date| Project name: hinnant-date
hinnant-date| Project version: 3.0.1
hinnant-date| C++ compiler for the host machine: c++ (gcc 13.3.0 "c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0")
hinnant-date| C++ linker for the host machine: c++ ld.bfd 2.42
hinnant-date| Build targets in project: 0
hinnant-date| Subproject hinnant-date finished.

Dependency date from subproject subprojects/hinnant-date found: YES 3.0.1
Run-time dependency rapidjson found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency RapidJSON
Downloading rapidjson source from https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz
Downloading file of unknown size.
Downloading rapidjson patch from https://wrapdb.mesonbuild.com/v2/rapidjson_1.1.0-2/get_patch

Executing subproject rapidjson

rapidjson| Project name: rapidjson
rapidjson| Project version: 1.1.0
rapidjson| C++ compiler for the host machine: c++ (gcc 13.3.0 "c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0")
rapidjson| C++ linker for the host machine: c++ ld.bfd 2.42
rapidjson| Build targets in project: 0
rapidjson| Subproject rapidjson finished.

Dependency RapidJSON from subproject subprojects/rapidjson-1.1.0 found: YES 1.1.0
Checking if "std::atomic" : links: YES
Checking if "std::atomic<uint64_t>" : links: YES
Run-time dependency openssl found: YES 3.0.13
Run-time dependency libevent found: YES 2.1.12-stable
Run-time dependency libevent_pthreads found: YES 2.1.12-stable
Run-time dependency dl found: YES
Configuring version.h using configuration
Program git found: YES (/usr/bin/git)
Build targets in project: 1
NOTICE: Future-deprecated features used:

  • 0.56.0: {'meson.source_root'}

pistache 0.3.0

Subprojects
hinnant-date : YES
rapidjson : YES

User defined options
default_library : static
prefix : /tmp/pistache/install
PISTACHE_FORCE_LIBEVENT: true
PISTACHE_USE_RAPIDJSON : true
PISTACHE_USE_SSL : true

Found ninja-1.11.1 at /usr/bin/ninja

  • meson compile
    [1/37] Compiling C++ object src/libpistache.a.p/common_pist_clock_gettime.cc.o
    [2/37] Compiling C++ object src/libpistache.a.p/common_pist_fcntl.cc.o
    [3/37] Compiling C++ object src/libpistache.a.p/common_pist_filefns.cc.o
    [4/37] Compiling C++ object src/libpistache.a.p/common_pist_sockfns.cc.o
    [5/37] Compiling C++ object src/libpistache.a.p/common_pist_check.cc.o
    [6/37] Compiling C++ object src/libpistache.a.p/common_pist_ifaddrs.cc.o
    [7/37] Compiling C++ object src/libpistache.a.p/common_pist_resource.cc.o
    [8/37] Compiling C++ object src/libpistache.a.p/common_net.cc.o
    [9/37] Compiling C++ object src/libpistache.a.p/common_base64.cc.o
    [10/37] Compiling C++ object src/libpistache.a.p/common_pist_strerror_r.cc.o
    [11/37] Compiling C++ object src/libpistache.a.p/common_ps_basename.cc.o
    [12/37] Compiling C++ object src/libpistache.a.p/common_os.cc.o
    [13/37] Compiling C++ object src/libpistache.a.p/common_pist_syslog.cc.o
    [14/37] Compiling C++ object src/libpistache.a.p/common_ps_sendfile.cc.o
    [15/37] Compiling C++ object src/libpistache.a.p/common_ps_strl.cc.o
    [16/37] Compiling C++ object src/libpistache.a.p/common_pist_timelog.cc.o
    [17/37] Compiling C++ object src/libpistache.a.p/common_string_logger.cc.o
    [18/37] Compiling C++ object src/libpistache.a.p/common_cookie.cc.o
    [19/37] Compiling C++ object src/libpistache.a.p/common_stream.cc.o
    [20/37] Compiling C++ object src/libpistache.a.p/common_eventmeth.cc.o
    [21/37] Compiling C++ object src/libpistache.a.p/common_mime.cc.o
    [22/37] Compiling C++ object src/libpistache.a.p/common_timer_pool.cc.o
    [23/37] Compiling C++ object src/libpistache.a.p/common_peer.cc.o
    [24/37] Compiling C++ object src/libpistache.a.p/common_http_headers.cc.o
    [25/37] Compiling C++ object src/libpistache.a.p/common_http_header.cc.o
    [26/37] Compiling C++ object src/libpistache.a.p/common_tcp.cc.o
    [27/37] Compiling C++ object src/libpistache.a.p/common_reactor.cc.o
    [28/37] Compiling C++ object src/libpistache.a.p/common_utils.cc.o
    [29/37] Compiling C++ object src/libpistache.a.p/common_http_defs.cc.o
    [30/37] Compiling C++ object src/libpistache.a.p/common_description.cc.o
    [31/37] Compiling C++ object src/libpistache.a.p/server_endpoint.cc.o
    [32/37] Compiling C++ object src/libpistache.a.p/common_http.cc.o
    [33/37] Compiling C++ object src/libpistache.a.p/common_transport.cc.o
    [34/37] Compiling C++ object src/libpistache.a.p/server_listener.cc.o
    [35/37] Compiling C++ object src/libpistache.a.p/client_client.cc.o
    [36/37] Compiling C++ object src/libpistache.a.p/server_router.cc.o
    [37/37] Linking static target src/libpistache.a
    INFO: autodetecting backend as ninja
    INFO: calculating backend command to run: /usr/bin/ninja
  • meson install
    ninja: Entering directory `/tmp/build/pistache-0.4.26/build'
    ninja: no work to do.
    Installing subdir /tmp/build/pistache-0.4.26/include/pistache/serializer to /tmp/pistache/install/include/pistache/serializer
    Installing /tmp/build/pistache-0.4.26/include/pistache/serializer/rapidjson.h to /tmp/pistache/install/include/pistache/serializer
    Installing src/libpistache.a to /tmp/pistache/install/lib/x86_64-linux-gnu
    Installing /tmp/build/pistache-0.4.26/include/pistache/async.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/base64.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/client.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/common.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/config.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/cookie.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/date_wrapper.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/description.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/em_socket_t.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/emosandlibevdefs.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/endpoint.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/eventmeth.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/errors.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/flags.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/http_defs.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/http.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/http_header.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/http_headers.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/iterator_adapter.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/listener.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/log.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/mailbox.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/mime.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/meta.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/net.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/os.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/peer.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_check.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_clock_gettime.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_fcntl.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_filefns.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_ifaddrs.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_quote.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_resource.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_sockfns.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_strerror_r.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_syslog.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pist_timelog.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/prototype.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/ps_basename.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/ps_sendfile.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/ps_strl.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/pst_errno.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/reactor.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/route_bind.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/router.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/ssl_wrappers.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/stream.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/string_logger.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/tcp.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/timer_pool.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/transport.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/type_checkers.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/typeid.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/utils.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/view.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/include/pistache/winornix.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/build/include/pistache/version.h to /tmp/pistache/install/include/pistache
    Installing /tmp/build/pistache-0.4.26/build/meson-private/libpistache.pc to /tmp/pistache/install/lib/x86_64-linux-gnu/pkgconfig
  • g++ example.cpp -o example -std=c++17 -I/tmp/pistache/install/include /tmp/pistache/install/lib/x86_64-linux-gnu/libpistache.a -lssl -lcrypto -levent -levent_pthreads -lpthread
  • ./example
    *** stack smashing detected ***: terminated
    Aborted (core dumped)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions