summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2022-12-20 16:51:26 (GMT)
committerGitHub <noreply@github.com>2022-12-20 16:51:26 (GMT)
commit44892d45b038f919b0378590a776580a9d73b291 (patch)
tree51599344059fa90691d68a8169b8029b783a687c /Lib/http
parentcb60b6131bc2bb11c48a15f808914d8b242b9fc5 (diff)
downloadcpython-44892d45b038f919b0378590a776580a9d73b291.zip
cpython-44892d45b038f919b0378590a776580a9d73b291.tar.gz
cpython-44892d45b038f919b0378590a776580a9d73b291.tar.bz2
gh-99576: Fix cookiejar file that was not truncated for some classes (GH-99616)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/cookiejar.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
index b0161a8..e3df007 100644
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -1890,7 +1890,10 @@ class LWPCookieJar(FileCookieJar):
if self.filename is not None: filename = self.filename
else: raise ValueError(MISSING_FILENAME_TEXT)
- with os.fdopen(os.open(filename, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
+ with os.fdopen(
+ os.open(filename, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600),
+ 'w',
+ ) as f:
# There really isn't an LWP Cookies 2.0 format, but this indicates
# that there is extra information in here (domain_dot and
# port_spec) while still being compatible with libwww-perl, I hope.
@@ -2081,7 +2084,10 @@ class MozillaCookieJar(FileCookieJar):
if self.filename is not None: filename = self.filename
else: raise ValueError(MISSING_FILENAME_TEXT)
- with os.fdopen(os.open(filename, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
+ with os.fdopen(
+ os.open(filename, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600),
+ 'w',
+ ) as f:
f.write(NETSCAPE_HEADER_TEXT)
now = time.time()
for cookie in self: