[utils] setproctitle: Fix NUL termination (#17724)

Authored by: doe1080
This commit is contained in:
doe1080
2026-09-27 19:40:54 +02:00
committed by GitHub
parent f45f14bd79
commit 39b31b2755
2 changed files with 10 additions and 3 deletions
+9
View File
@@ -107,6 +107,7 @@ from yt_dlp.utils import (
sanitize_filename, sanitize_filename,
sanitize_path, sanitize_path,
sanitize_url, sanitize_url,
setproctitle,
shell_quote, shell_quote,
strftime_or_none, strftime_or_none,
smuggle_url, smuggle_url,
@@ -613,6 +614,14 @@ class TestUtil(unittest.TestCase):
self.assertEqual(res_url, url) self.assertEqual(res_url, url)
self.assertEqual(res_data, {'a': 'b', 'c': 'd'}) self.assertEqual(res_data, {'a': 'b', 'c': 'd'})
@unittest.mock.patch('ctypes.cdll.LoadLibrary')
def test_setproctitle(self, load_library):
for title in ('yt-dlp', 'café'):
with self.subTest(title=title):
setproctitle(title)
buf = load_library.return_value.prctl.call_args.args[1]
self.assertEqual(bytes(buf), title.encode() + b'\0')
def test_shell_quote(self): def test_shell_quote(self):
args = ['ffmpeg', '-i', 'ñ€ß\'.mp4'] args = ['ffmpeg', '-i', 'ñ€ß\'.mp4']
self.assertEqual( self.assertEqual(
+1 -3
View File
@@ -1959,9 +1959,7 @@ def setproctitle(title):
except OSError: except OSError:
return return
title_bytes = title.encode() buf = ctypes.create_string_buffer(title.encode())
buf = ctypes.create_string_buffer(len(title_bytes))
buf.value = title_bytes
try: try:
# PR_SET_NAME = 15 Ref: /usr/include/linux/prctl.h # PR_SET_NAME = 15 Ref: /usr/include/linux/prctl.h
libc.prctl(15, buf, 0, 0, 0) libc.prctl(15, buf, 0, 0, 0)