FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-159864: Fix syslog.openlog() crash with concurrent sys.argv changes by espressolee · Pull Request #159884 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
23 changes: 23 additions & 0 deletions Lib/test/test_free_threading/test_syslog.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import unittest
import threading

from test import support
from test.support import import_helper, threading_helper
from test.support.threading_helper import run_concurrently

Expand Down Expand Up @@ -39,6 +41,27 @@ def worker():
nthreads=NTHREADS,
)

def test_racing_openlog_argv(self):
# gh-159864: openlog() without an ident reads sys.argv[0] while
# another thread replaces it.
argv = ["prog"]

def opener():
for _ in range(1000):
syslog.openlog()

def writer():
for i in range(1000):
argv[0] = f"prog-{i}"

with support.swap_attr(sys, "argv", argv):
try:
run_concurrently(
worker_func=[opener] * (NTHREADS - 1) + [writer],
)
finally:
syslog.closelog()


if __name__ == "__main__":
unittest.main()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in :func:`syslog.openlog` under the free-threaded build when
:data:`sys.argv` is modified concurrently.
3 changes: 1 addition & 2 deletions Modules/syslogmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ syslog_get_argv(void)
return NULL;
}

scriptobj = PyList_GetItem(argv, 0);
Py_XINCREF(scriptobj);
scriptobj = PyList_GetItemRef(argv, 0);
Py_DECREF(argv);
if (scriptobj == NULL) {
PyErr_Clear();
Expand Down
Loading

Back | FazBrowse Home | New Git URL