aboutsummaryrefslogtreecommitdiffstats
path: root/ruby-runner.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-10-20 18:09:47 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-10-21 14:05:20 +0900
commit6d1ed3def8a79047b3e55dd3e6ddb83544794e02 (patch)
tree1533ed106526b35f3b6ea9e15909387b487c0654 /ruby-runner.c
parent55d954721e25ada90482f6d3f751a12fc982620b (diff)
downloadruby-6d1ed3def8a79047b3e55dd3e6ddb83544794e02.tar.gz
Avoid duplicate path in library paths
Diffstat (limited to 'ruby-runner.c')
-rw-r--r--ruby-runner.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ruby-runner.c b/ruby-runner.c
index bbc2b78fa0..5731ea5287 100644
--- a/ruby-runner.c
+++ b/ruby-runner.c
@@ -25,12 +25,24 @@ insert_env_path(const char *envname, const char *paths, size_t size, int prepend
char *e = malloc(size+n+1);
size_t pos = 0;
if (prepend) {
+ if (size == n || (size < n && env[size] == PATH_SEP)) {
+ if (strncmp(paths, env, size) == 0) {
+ free(e);
+ return;
+ }
+ }
memcpy(e, paths, pos = size-1);
e[pos++] = PATH_SEP;
}
memcpy(e+pos, env, n);
pos += n;
if (!prepend) {
+ if (size == n || (size < n && env[n-size-1] == PATH_SEP)) {
+ if (strncmp(paths, &env[n-size], size) == 0) {
+ free(e);
+ return;
+ }
+ }
e[pos++] = PATH_SEP;
memcpy(e+pos, paths, size-1);
pos += size-1;