Skip to content

Commit 518c370

Browse files
committed
perl.c: Add locks around a *environ access
When reading the environment, a read lock is needed; when writing, a write lock.
1 parent de47acd commit 518c370

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

perl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@ dup_environ(pTHX)
16651665

16661666
size_t n_entries = 0, vars_size = 0;
16671667

1668+
ENV_READ_LOCK;
16681669
for (char **ep = environ; *ep; ++ep) {
16691670
++n_entries;
16701671
vars_size += strlen(*ep) + 1;
@@ -1682,9 +1683,14 @@ dup_environ(pTHX)
16821683
new_environ[i] = (char *) CopyD(environ[i], vars + copied, len, char);
16831684
copied += len;
16841685
}
1686+
1687+
ENV_READ_UNLOCK;
1688+
16851689
new_environ[n_entries] = NULL;
16861690

1691+
ENV_LOCK;
16871692
environ = new_environ;
1693+
ENV_UNLOCK;
16881694
/* Store a pointer in a global variable to ensure it's always reachable so
16891695
* LeakSanitizer/Valgrind won't complain about it. We can't ever free it.
16901696
* Even if libc allocates a new environ, it's possible that some of its

0 commit comments

Comments
 (0)