about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVarun Madiath <git@madiathv.com>2023-07-19 17:38:34 -0400
committerAnderson Torres <torres.anderson.85@protonmail.com>2023-07-20 12:28:14 -0300
commit4b7ad2c7eab37e3ade26e560a5c01a4b5a4321c3 (patch)
treec0646fd277eb034bcef2ea5a3e5937f1c5a82418
parent1a335c25e33d7fbc570afdabf9cae16fe78cf295 (diff)
jesec-rtorrent: Add patch to prevent segfault
-rw-r--r--pkgs/applications/networking/p2p/jesec-rtorrent/avoid-stack-overflow-for-lockfile-buf.patch30
-rw-r--r--pkgs/applications/networking/p2p/jesec-rtorrent/default.nix4
2 files changed, 34 insertions, 0 deletions
diff --git a/pkgs/applications/networking/p2p/jesec-rtorrent/avoid-stack-overflow-for-lockfile-buf.patch b/pkgs/applications/networking/p2p/jesec-rtorrent/avoid-stack-overflow-for-lockfile-buf.patch
new file mode 100644
index 0000000000000..2a20b157a2fc8
--- /dev/null
+++ b/pkgs/applications/networking/p2p/jesec-rtorrent/avoid-stack-overflow-for-lockfile-buf.patch
@@ -0,0 +1,30 @@
+From dd4a96073d4a60ca8fff55be6ea6b17018de96a8 Mon Sep 17 00:00:00 2001
+From: Varun Madiath <git@madiathv.com>
+Date: Wed, 19 Jul 2023 15:30:57 -0400
+Subject: [PATCH] utils: lockfile: avoid stack overflow for lockfile buffer
+
+Original patch by @cyphar was submitted to rakshasa/rtorrent at
+https://github.com/rakshasa/rtorrent/pull/1169.
+
+Observed the segfault on nixos-unstable.
+---
+ src/utils/lockfile.cc | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/utils/lockfile.cc b/src/utils/lockfile.cc
+index 76e4b8f..441f5c8 100644
+--- a/src/utils/lockfile.cc
++++ b/src/utils/lockfile.cc
+@@ -75,7 +75,8 @@ Lockfile::try_lock() {
+   int  pos = ::gethostname(buf, 255);
+ 
+   if (pos == 0) {
+-    ::snprintf(buf + std::strlen(buf), 255, ":+%i\n", ::getpid());
++    ssize_t len = std::strlen(buf);
++    ::snprintf(buf + len, 255 - len, ":+%i\n", ::getpid());
+     ssize_t __attribute__((unused)) result = ::write(fd, buf, std::strlen(buf));
+   }
+ 
+-- 
+2.41.0
+
diff --git a/pkgs/applications/networking/p2p/jesec-rtorrent/default.nix b/pkgs/applications/networking/p2p/jesec-rtorrent/default.nix
index 5a0cebc528191..94c1994bd0809 100644
--- a/pkgs/applications/networking/p2p/jesec-rtorrent/default.nix
+++ b/pkgs/applications/networking/p2p/jesec-rtorrent/default.nix
@@ -21,6 +21,10 @@ stdenv.mkDerivation rec {
     hash = "sha256-i7c1jSawHshj1kaXl8tdpelIKU24okeg9K5/+ht6t2k=";
   };
 
+  patches = [
+    ./avoid-stack-overflow-for-lockfile-buf.patch
+  ];
+
   passthru = {
     inherit libtorrent;
   };