mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-10-16 13:38:07 -07:00
[utils] setproctitle: Fix NUL termination (#17724)
Authored by: doe1080
This commit is contained in:
@@ -107,6 +107,7 @@ from yt_dlp.utils import (
|
||||
sanitize_filename,
|
||||
sanitize_path,
|
||||
sanitize_url,
|
||||
setproctitle,
|
||||
shell_quote,
|
||||
strftime_or_none,
|
||||
smuggle_url,
|
||||
@@ -613,6 +614,14 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertEqual(res_url, url)
|
||||
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):
|
||||
args = ['ffmpeg', '-i', 'ñ€ß\'.mp4']
|
||||
self.assertEqual(
|
||||
|
||||
@@ -1959,9 +1959,7 @@ def setproctitle(title):
|
||||
except OSError:
|
||||
return
|
||||
|
||||
title_bytes = title.encode()
|
||||
buf = ctypes.create_string_buffer(len(title_bytes))
|
||||
buf.value = title_bytes
|
||||
buf = ctypes.create_string_buffer(title.encode())
|
||||
try:
|
||||
# PR_SET_NAME = 15 Ref: /usr/include/linux/prctl.h
|
||||
libc.prctl(15, buf, 0, 0, 0)
|
||||
|
||||
Reference in New Issue
Block a user