← Back to Pull requests

MDEV-41161 Add OpenBSD getexecpath() support to my_get_exepath() #5686

Open
brad0 opened this pull request with 74 lines diff across 6 files
View on GitHub
brad0 brad0 commented on Sep 17, 2026 03:12 UTC
Author

my_get_exepath() had no OpenBSD implementation and fell back to
resolving argv[0] with my_realpath(). mariadb-backup calls it before
MY_INIT(), so when realpath() fails, my_realpath() setting my_errno
dereferences a NULL my_thread_var and mariadb-backup crashes at startup.
This happens whenever it is run via PATH, since a bare argv[0] does not
resolve relative to the current directory.

Use getexecpath(3), detected at configure time, to get the executable
path from the kernel as is already done on Linux, FreeBSD, NetBSD,
macOS and Windows, so the fallback is no longer reached on OpenBSD.

Diff: 74 lines (+74 / -0) across 6 files Reviewer: gkodinov Review duration: 103675m
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.43) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 74 lines diff across 6 files
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
85%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.258
Real PR Conversation Timeline
20 items
brad0 brad0 commented on Sep 17, 2026 04:43 UTC
Author

I forgot to target the oldest branch not latest (main).

gkodinov gkodinov commented on code on Sep 17, 2026 07:54 UTC
Code Review
mysys/my_getexe.c:1
@@ -17,7 +17,7 @@
 #include <my_sys.h>
 
 #ifdef _WIN32
-#elif defined(__linux__)
+#elif defined(__linux__) || (defined(__OpenBSD__) && defined(HAVE_GETEXECPATH))

Frankly I'd prefer keeping a separate #elif branch but that's just me.
Also, why do you need to also check if it's openbsd if you've already checked if you have the function?

gkodinov gkodinov commented on code on Sep 17, 2026 07:55 UTC
Code Review
mysys/my_getexe.c:1
@@ -58,6 +58,9 @@ int my_get_exepath(char *buf, size_t size, const char *argv0)
   int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
   if (sysctl(mib, 4, buf, &size, NULL, 0) == 0)
     return 0;
+#elif defined(__OpenBSD__) && defined(HAVE_GETEXECPATH)

I'd say just #elif defined(HAVE_GETEXECPATH) should do.

gkodinov gkodinov requested changes on Sep 17, 2026 08:00 UTC
Changes Requested Reviewer

Thank you for your contribution! This is a preliminary review.

First of all: can you please describe how this works on the OS prior to your fix and how does your fix change the functionality?
I believe not significantly. But please prove me wrong if it's otherwise.

I need the exact comparison to understand if this is a bug fix or a featurette add-on.

If the belief I've expressed above is even remotely rooted in reality, I'd say that this needs to be rebased on the main branch.

If it's a bug fix, it needs to go to either 11.4 or 10.11 (depending on severity).

Please clarify.

In the meantime, I have some formal suggestions on the diff itself.
And I'd very much appreciate a regression test, even if it is specific to the OS at hand.

brad0 brad0 commented on code on Sep 17, 2026 08:17 UTC
Code Review
mysys/my_getexe.c:1
@@ -17,7 +17,7 @@
 #include <my_sys.h>
 
 #ifdef _WIN32
-#elif defined(__linux__)
+#elif defined(__linux__) || (defined(__OpenBSD__) && defined(HAVE_GETEXECPATH))

I was going back and forth and erred on the side of reduced duplication. But I can do that as well.
Just the style I've been going with and I guess the plan was to eventually just drop the check

gkodinov gkodinov requested changes on Sep 17, 2026 08:31 UTC
Changes Requested Reviewer

The diff looks ok now. Please, as requested, also rebase, think of a possible test case and describe the pre- and post- effects.

brad0 brad0 commented on Sep 17, 2026 08:38 UTC
Author
gkodinov gkodinov requested changes on Sep 24, 2026 11:18 UTC
Changes Requested Reviewer

Thank you for your continued work on this.

I'd really appreciate an explanation on how this is different from the current situation. I understand the API is going to get called. But, how is that functionally different? We need to document the functional change so that our users know what to expect. And, personally, I also need it to determine if this is acceptable from a functionality standpoint and whether it's a feature or a bug fix. And hence the relevant target version.

I also need you to amend your commit with a commit message that's compliant to the MariaDB contribution guidelines.

Thanks in advance.

grooverdan grooverdan commented on Oct 01, 2026 21:48 UTC
Contributor

Note, also include a negative find in cmake/os/WindowsCache.cmake like other function checks that are known not to exist on Windows. It make their build faster.

CLAassistant CLAassistant commented on Oct 19, 2026 02:33 UTC
Contributor
gkodinov gkodinov requested changes on Oct 20, 2026 09:30 UTC
Changes Requested Reviewer

None of the prior review remarks seems addressed. Can you please attend to these?

gkodinov gkodinov commented on code on Oct 21, 2026 11:41 UTC
Code Review
mysql-test/suite/mariabackup/export_argv0.test:1
@@ -0,0 +1,57 @@
+#
+# MDEV-41161 my_get_exepath() must not depend on argv[0]
+#
+# mariadb-backup --prepare --export re-executes itself as --mariadbd,
+# using the path from my_get_exepath(). Run it with an argv[0] that
+# does not name the executable; this only works when my_get_exepath()
+# asks the OS for the path instead of resolving argv[0].
+#
+--source include/have_innodb.inc
+--source include/not_windows.inc
+
+# Only platforms with a native my_get_exepath() implementation
+--perl
+open(F, '>', "$ENV{MYSQLTEST_VARDIR}/tmp/exepath_os.inc") or die;
+print F "let \$exepath_os= $^O;\n";
+close F;
+EOF
+--source $MYSQLTEST_VARDIR/tmp/exepath_os.inc
+--remove_file $MYSQLTEST_VARDIR/tmp/exepath_os.inc
+if (!`SELECT '$exepath_os' IN ('linux','freebsd','netbsd','openbsd','darwin')`)

FWIW, my_get_exepath() does call GetModuleFileNameA() on windows. If it's not too much to ask, could you maybe test that? It's OK as is, just saying that I believe there's an OS missing :)

gkodinov gkodinov requested changes on Oct 21, 2026 11:43 UTC
Changes Requested Reviewer

Thank you for the awesome test case! And the comments in it!

I believe I understand the change now. Is this a fair summarization of it below? If it is please confirm and ask for my review again. If not, please propose a better alternative.
As stated, I need something to put in the Jira so that it gets documented well.

-------------
Some MariaDB binaries (e.g. mariadb-backup) might need to fetch the program name for the running process. E.g. they might need to respawn themselves so they'd need that.
But reading argv[0] is not a very reliable way to do this: some OSes might spoof it.
So the code takes extra measures to acquire the actual executable name from the OS, where available.
On OpenBSD there is a getexecpath() API that provides this. But it was not called by my_get_exepath(). As a result, on that OS, it was falling back to argv[0] which is not a very reliable source as already established.

Fixed my_get_exepath() to use getexecpath() if available. Added a test to cover this.

brad0 brad0 commented on Oct 21, 2026 11:51 UTC
Author

Thank you for the awesome test case! And the comments in it!

> I believe I understand the change now. Is this a fair summarization of it below? If it is please confirm and ask for my review again. If not, please propose a better alternative. As stated, I need something to put in the Jira so that it gets documented well.

> Some MariaDB binaries (e.g. mariadb-backup) might need to fetch the program name for the running process. E.g. they might need to respawn themselves so they'd need that. But reading argv[0] is not a very reliable way to do this: some OSes might spoof it. So the code takes extra measures to acquire the actual executable name from the OS, where available. On OpenBSD there is a getexecpath() API that provides this. But it was not called by my_get_exepath(). As a result, on that OS, it was falling back to argv[0] which is not a very reliable source as already established.

> Fixed my_get_exepath() to use getexecpath() if available. Added a test to cover this.

That is correct.

brad0 brad0 commented on code on Oct 21, 2026 11:52 UTC
Code Review
mysql-test/suite/mariabackup/export_argv0.test:1
@@ -0,0 +1,57 @@
+#
+# MDEV-41161 my_get_exepath() must not depend on argv[0]
+#
+# mariadb-backup --prepare --export re-executes itself as --mariadbd,
+# using the path from my_get_exepath(). Run it with an argv[0] that
+# does not name the executable; this only works when my_get_exepath()
+# asks the OS for the path instead of resolving argv[0].
+#
+--source include/have_innodb.inc
+--source include/not_windows.inc
+
+# Only platforms with a native my_get_exepath() implementation
+--perl
+open(F, '>', "$ENV{MYSQLTEST_VARDIR}/tmp/exepath_os.inc") or die;
+print F "let \$exepath_os= $^O;\n";
+close F;
+EOF
+--source $MYSQLTEST_VARDIR/tmp/exepath_os.inc
+--remove_file $MYSQLTEST_VARDIR/tmp/exepath_os.inc
+if (!`SELECT '$exepath_os' IN ('linux','freebsd','netbsd','openbsd','darwin')`)

Yes, you are right. Let me correct that. I don't know if this test will work there but I guess lets see when it runs for CI?

gkodinov gkodinov approved these changes on Oct 21, 2026 12:09 UTC
Approved Reviewer

LGTM. Thank you! Please stay tuned for the final review.

brad0 brad0 commented on Nov 03, 2026 03:07 UTC
Author

Ping.

gkodinov gkodinov commented on Nov 03, 2026 12:39 UTC
Contributor

FYI: According to our development cycle we work on bugs In the following periods 15 Mar-30 Apr, 15 Jun-30 Jul, 15 Sep-30 Oct and 15 Dec-31 Jan. So, please, expect to get a review somewhere between these two dates and the goal is to have your PR merged before the second date

brad0 brad0 commented on Nov 03, 2026 16:12 UTC
Author

FYI: According to our development cycle we work on bugs In the following periods 15 Mar-30 Apr, 15 Jun-30 Jul, 15 Sep-30 Oct and 15 Dec-31 Jan. So, please, expect to get a review somewhere between these two dates and the goal is to have your PR merged before the second date

Oh, I was not aware of that. Thanks.

Reviewers
Assignees
brad0 brad0
Labels
risk: low confidence: 85.4% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 43.1% (MEDIUM) · Higher = larger blast radius
43.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 85.4% · Lower = rushed or shallow review
85.4%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 6.3% · Safe to merge
6.3%
Repository