Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mailbox.mbox.flush() loses mailbox owner #117467

Closed
Labels
3.12only security fixes3.13bugs and security fixestopic-emailtype-bugAn unexpected behavior, bug, or error
@softins

Description

@softins

In theflush() method for mbox mailboxes, after writing the new file, it correctly copies the file modes from the old file to the new one:

cpython/Lib/mailbox.py

Lines 753 to 755 in027fa2e

# Make sure the new file's mode is the same as the old file's
mode=os.stat(self._path).st_mode
os.chmod(new_file.name,mode)

However, it doesn't copy the user.group ownership of the old file to the new one, and I think it should.

I implemented a python program to modify a mailbox, in this case to delete old messages from a spam folder. The program runs as root, so that it can operate on folders belonging to different users without having to suid to each user. I found that on flushing after any changes, the mailbox was owned by root.root instead of by its original owner.

Suggest the following code instead:

        # Make sure the new file's mode and owner are the same as the old file's        info = os.stat(self._path)        os.chmod(new_file.name, info.st_mode)        try:                os.chown(new_file.name, info.st_uid, info.st_gid)        except OSError:                pass

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixestopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp