Skip to content

Commit 66d1b3c

Browse files
Tomi Ollilambolivar-nordic
authored andcommitted
kconfig: kconfiglib.py: Backup files only
The _save_old() to return early if <filename> is not file (or symlink to a file). This is simplest alternative to avoid attempt to rename /dev/null (which could succeed). This also keeps fifos (perhaps nonexistent potential usage but this is nicer). If <filename> were directory or socket, after shutil.copyfile(), writing to the file (by caller, _write_config()), would fail. Fixes #31362 Co-authored-by: Marti Bolivar <[email protected]> Signed-off-by: Tomi Ollila <[email protected]>
1 parent 3c3504f commit 66d1b3c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/kconfig/kconfiglib.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,8 +1545,7 @@ def write_config(self, filename=None, header=None, save_old=True,
15451545
written.
15461546
15471547
Errors are silently ignored if <filename>.old cannot be written (e.g.
1548-
due to being a directory, or <filename> being something like
1549-
/dev/null).
1548+
due to permissions errors).
15501549
15511550
verbose (default: None):
15521551
Limited backwards compatibility to prevent crashes. A warning is
@@ -6392,6 +6391,12 @@ def _touch_dep_file(path, sym_name):
63926391
def _save_old(path):
63936392
# See write_config()
63946393

6394+
if not os.path.isfile(path):
6395+
# Backup only files (and symlinks to files). Simplest alternative
6396+
# to avoid e.g. (potentially successful attempt to) rename /dev/null
6397+
# (and to keep fifos).
6398+
return
6399+
63956400
def copy(src, dst):
63966401
# Import as needed, to save some startup time
63976402
import shutil
@@ -6416,8 +6421,7 @@ def copy(src, dst):
64166421
except Exception:
64176422
# Ignore errors from 'path' missing as well as other errors.
64186423
# <filename>.old file is usually more of a nice-to-have, and not worth
6419-
# erroring out over e.g. if <filename>.old happens to be a directory or
6420-
# <filename> is something like /dev/null.
6424+
# erroring out over e.g. if <filename>.old happens to be a directory.
64216425
pass
64226426

64236427

0 commit comments

Comments
 (0)