commit:     e5322bbd5c9ad3558bfd44186fa8a5ce1ba69955
Author:     Haelwenn (lanodan) Monnier <contact <AT> hacktivis <DOT> me>
AuthorDate: Wed Jun 25 23:13:06 2025 +0000
Commit:     Haelwenn Monnier <contact <AT> hacktivis <DOT> me>
CommitDate: Wed Jun 25 23:13:55 2025 +0000
URL:        https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=e5322bbd

dev-lang/hare: add patch to fix os::clearenv

This patch has been applied upstream: 
https://git.sr.ht/~sircmpwn/hare/commit/4039f65285e5fbd89192319e52cd8fa0ea1ec214

And reported here: 
https://lists.sr.ht/~sircmpwn/hare-dev/%[email protected]%3E#%3CDAVE0JNU5ATC.10TZVZM0C3UB3
 <AT> willowbarraco.fr%3E

Signed-off-by: Haelwenn (lanodan) Monnier <contact <AT> hacktivis.me>

 .../files/hare-0.25.2-os_exec-fix-clearenv.patch   | 93 ++++++++++++++++++++++
 ...hare-0.25.2-r1.ebuild => hare-0.25.2-r2.ebuild} |  4 +
 2 files changed, 97 insertions(+)

diff --git a/dev-lang/hare/files/hare-0.25.2-os_exec-fix-clearenv.patch 
b/dev-lang/hare/files/hare-0.25.2-os_exec-fix-clearenv.patch
new file mode 100644
index 0000000000..47ec815eac
--- /dev/null
+++ b/dev-lang/hare/files/hare-0.25.2-os_exec-fix-clearenv.patch
@@ -0,0 +1,93 @@
+From 4039f65285e5fbd89192319e52cd8fa0ea1ec214 Mon Sep 17 00:00:00 2001
+From: Armin Preiml <[email protected]>
+Date: Wed, 25 Jun 2025 10:57:23 +0200
+Subject: [PATCH hare] os::exec: fix clearenv
+
+Signed-off-by: Armin Preiml <[email protected]>
+---
+ os/exec/+freebsd/platform_cmd.ha |  2 +-
+ os/exec/+linux/platform_cmd.ha   |  2 +-
+ os/exec/+netbsd/platform_cmd.ha  |  2 +-
+ os/exec/+openbsd/platform_cmd.ha |  2 +-
+ os/exec/env+test.ha              | 19 +++++++++++++++++++
+ 5 files changed, 23 insertions(+), 4 deletions(-)
+
+diff --git a/os/exec/+freebsd/platform_cmd.ha 
b/os/exec/+freebsd/platform_cmd.ha
+index 2c0d972d..f328f9ac 100644
+--- a/os/exec/+freebsd/platform_cmd.ha
++++ b/os/exec/+freebsd/platform_cmd.ha
+@@ -91,7 +91,7 @@ fn platform_setenv(
+ 
+ fn platform_unsetenv(cmd: *command, key: str) (void | errors::invalid) = {
+       // XXX: This can be a binary search
+-      for (let i = 0z; i < len(cmd.env) - 1; i += 1) {
++      for (let i = 0z; i < len(cmd.env) && cmd.env[i] != null; i += 1) {
+               let e = c::tostr(cmd.env[i]: *const c::char)!;
+               if (strings::cut(e, "=").0 == key) {
+                       free(cmd.env[i]);
+diff --git a/os/exec/+linux/platform_cmd.ha b/os/exec/+linux/platform_cmd.ha
+index 1ec0ddd4..4bf65cb9 100644
+--- a/os/exec/+linux/platform_cmd.ha
++++ b/os/exec/+linux/platform_cmd.ha
+@@ -89,7 +89,7 @@ fn platform_setenv(
+ 
+ fn platform_unsetenv(cmd: *command, key: str) (void | errors::invalid) = {
+       // XXX: This can be a binary search
+-      for (let i = 0z; cmd.env[i] != null; i += 1) {
++      for (let i = 0z; i < len(cmd.env) && cmd.env[i] != null; i += 1) {
+               let e = c::tostr(cmd.env[i]: *const c::char)!;
+               if (strings::cut(e, "=").0 == key) {
+                       free(cmd.env[i]);
+diff --git a/os/exec/+netbsd/platform_cmd.ha b/os/exec/+netbsd/platform_cmd.ha
+index 2c26cff6..0ccd99bf 100644
+--- a/os/exec/+netbsd/platform_cmd.ha
++++ b/os/exec/+netbsd/platform_cmd.ha
+@@ -92,7 +92,7 @@ fn platform_setenv(
+ 
+ fn platform_unsetenv(cmd: *command, key: str) (void | errors::invalid) = {
+       // XXX: This can be a binary search
+-      for (let i = 0z; i < len(cmd.env) - 1; i += 1) {
++      for (let i = 0z; i < len(cmd.env) && cmd.env[i] != null; i += 1) {
+               let e = c::tostr(cmd.env[i]: *const c::char)!;
+               if (strings::cut(e, "=").0 == key) {
+                       free(cmd.env[i]);
+diff --git a/os/exec/+openbsd/platform_cmd.ha 
b/os/exec/+openbsd/platform_cmd.ha
+index 9826111f..d1e1f667 100644
+--- a/os/exec/+openbsd/platform_cmd.ha
++++ b/os/exec/+openbsd/platform_cmd.ha
+@@ -89,7 +89,7 @@ fn platform_setenv(
+ 
+ fn platform_unsetenv(cmd: *command, key: str) (void | errors::invalid) = {
+       // XXX: This can be a binary search
+-      for (let i = 0z; i < len(cmd.env) - 1; i += 1) {
++      for (let i = 0z; i < len(cmd.env) && cmd.env[i] != null; i += 1) {
+               let e = c::tostr(cmd.env[i]: *const c::char)!;
+               if (strings::cut(e, "=").0 == key) {
+                       free(cmd.env[i]);
+diff --git a/os/exec/env+test.ha b/os/exec/env+test.ha
+index cfd62733..e41395ad 100644
+--- a/os/exec/env+test.ha
++++ b/os/exec/env+test.ha
+@@ -43,3 +43,22 @@ use bufio;
+       io::close(rd)!;
+       wait(&proc)!;
+ };
++
++@test fn clearenv() void = {
++      let cmd = cmd("env")!;
++      clearenv(&cmd);
++      setenv(&cmd, "HARETEST", "single")!;
++
++      const (rd, wr) = pipe();
++      addfile(&cmd, os::stdout_file, wr)!;
++      let proc = start(&cmd)!;
++      io::close(wr)!;
++
++      let sc = bufio::newscanner(rd);
++      defer io::close(&sc)!;
++      for (let l => bufio::scan_line(&sc)!) {
++              assert(l == "HARETEST=single");
++      };
++      io::close(rd)!;
++      wait(&proc)!;
++};

diff --git a/dev-lang/hare/hare-0.25.2-r1.ebuild 
b/dev-lang/hare/hare-0.25.2-r2.ebuild
similarity index 95%
rename from dev-lang/hare/hare-0.25.2-r1.ebuild
rename to dev-lang/hare/hare-0.25.2-r2.ebuild
index 28a142b085..ea2e67a9fa 100644
--- a/dev-lang/hare/hare-0.25.2-r1.ebuild
+++ b/dev-lang/hare/hare-0.25.2-r2.ebuild
@@ -31,6 +31,10 @@ RDEPEND="${DEPEND}"
 # hare and haredoc are built by hare
 QA_FLAGS_IGNORED="usr/bin/hare usr/bin/haredoc"
 
+PATCHES=(
+       "${FILESDIR}/hare-0.25.2-os_exec-fix-clearenv.patch"
+)
+
 src_configure() {
        local target_arch
        case ${ARCH} in

Reply via email to