RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2009200 - python3 TimedRotatingFileHandler does not raise exception if given path is device (/dev/null) and turns it into a file
Summary: python3 TimedRotatingFileHandler does not raise exception if given path is de...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: python3
Version: 8.5
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Victor Stinner
QA Contact: Lukáš Zachar
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-09-30 07:30 UTC by dbodnarc
Modified: 2022-05-17 16:39 UTC (History)
3 users (show)

Fixed In Version: python3-3.6.8-43.el8
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-05-10 14:55:18 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Python 45401 0 None None None 2021-10-07 09:49:49 UTC
Red Hat Issue Tracker RHELPLAN-98547 0 None None None 2021-09-30 07:33:09 UTC
Red Hat Product Errata RHSA-2022:1986 0 None None None 2022-05-10 14:55:27 UTC

Description dbodnarc 2021-09-30 07:30:53 UTC
Description of problem:
We are running on RHEL8 a python3 script that collect logs with the python standard "logging" module TimedRotatingFileHandler. We have added, in a second moment, the possibility to avoid the logger to gather information, redirecting to the device "/dev/null" the output.
We know that using the module StreamHandler it would correctly redirect to the device "/dev/null", but as anticipated in title, we would expect from filehandlers to raise an exception if the filename is related to a device without change it to a file. 

Version-Release number of selected component (if applicable):
$ python3
Python 3.6.8 (default, Dec  5 2019, 15:45:45)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'3.6.8 (default, Dec  5 2019, 15:45:45) \n[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]'

How reproducible:

reporoducer.py:
------------------------8<------------------------8<------------------------
import logging
from logging.handlers import TimedRotatingFileHandler

def setup_logger(name, log_file_path, level=logging.INFO):
    """To setup as many loggers as you want"""
    logger = logging.getLogger(name)
    logger.setLevel(level)
    handler = TimedRotatingFileHandler(log_file_path, when="m", interval=1, backupCount=5)
    formatter = logging.Formatter('%(asctime)s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    return logger


logger_path = "/dev/null"
logger = setup_logger("logger", logger_path)
logger.info("")
------------------------8<------------------------8<------------------------

Steps to Reproduce:
# touch -t 09260100 /dev/null.2021-07-16
# stat /dev/null.2021-07-16
  File: '/dev/null.2021-07-16'
  Size: 10635           Blocks: 24         IO Block: 4096   regular file
Device: 5h/5d   Inode: 1794379367  Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:device_t:s0
Access: 2021-09-26 01:00:00.000000000 +0200
Modify: 2021-09-26 01:00:00.000000000 +0200
Change: 2021-09-27 14:50:14.050201303 +0200
 Birth: -
#
# python3 reproducer.py 
# ls -l /dev/null*
crw-rw-rw-. 1 root root  1, 3 Sep 27 14:35 /dev/null
-rw-r--r--. 1 root root 10635 Sep 27 14:51 /dev/null.2021-07-16
crw-rw-rw-. 1 root root  1, 3 Jul 16 20:53 /dev/null.2021-07-16.2021-07-16
-rw-r--r--. 1 root root 10635 Sep 26 01:00 /dev/null.2021-07-16.2021-09-26


Actual results:
# ls -l /dev/null*
crw-rw-rw-. 1 root root 1, 3 Oct 13  2020 /dev/null
# python3 reproducer.py 
# ls -l /dev/null*
-rw-r--r--. 1 root root  788 Sep 27 16:08 /dev/null

Expected results:
# ls -l /dev/null*
crw-rw-rw-. 1 root root 1, 3 Oct 13  2020 /dev/null
# python3 reproducer.py 
-- Exception xxx --
# ls -l /dev/null*
crw-rw-rw-. 1 root root 1, 3 Oct 13  2020 /dev/null

Comment 2 Victor Stinner 2021-10-07 09:49:49 UTC
I reported this issue to Python upstream: https://bugs.python.org/issue45401

Comment 5 Victor Stinner 2021-10-12 08:48:04 UTC
> I reported this issue to Python upstream: https://bugs.python.org/issue45401

The issue has been fixed.

Comment 12 errata-xmlrpc 2022-05-10 14:55:18 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: python3 security update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:1986

Comment 13 Victor Stinner 2022-05-17 16:39:20 UTC
This bug was really bad. It's convenient to use /dev/null filename to ignore logs. It's good that this bug got fixed in RHEL8.


Note You need to log in before you can comment on or make changes to this bug.