diff mbox series

[6/6] lib/oe/package: fix logic error in file permission checks

Message ID 20261019145837.2487873-6-ross.burton@arm.com
State New
Headers show
Series [1/6] lib/oe/sstatesig: cache the user/group lookups in OEOuthashBasic | expand

Commit Message

Ross Burton Oct. 19, 2026, 2:58 p.m. UTC
Various bits of package.py manipulate executables on disk, for example
stripping the binary or extracting the debug info.  Some recipes write
read-only libraries (notably, perl-native) so we need to check for this
and add writable permissions briefly.

However, this logic was incorrect.  The line is:

    if not os.access(file, os.W_OK) or os.access(file, os.R_OK):

'not' has higher precedence than 'or', so this is "if not writable, or
if readable" so we were always changing the permissions, even on files
we can read and write.

The desired behaviour is to change permissions if we can't read or write
the file, which can be done in a single access check:

    if not os.access(file, os.R_OK | os.W_OK):

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/lib/oe/package.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index e706e359cc3..a0bde50ed63 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -30,7 +30,7 @@  def runstrip(file, elftype, strip, extra_strip_sections=''):
     # 16 - kernel module
 
     newmode = None
-    if not os.access(file, os.W_OK) or os.access(file, os.R_OK):
+    if not os.access(file, os.R_OK | os.W_OK):
         origmode = os.stat(file)[stat.ST_MODE]
         newmode = origmode | stat.S_IWRITE | stat.S_IREAD
         os.chmod(file, newmode)
@@ -780,7 +780,7 @@  def splitdebuginfo(file, dvar, dv, d):
     objcopy = d.getVar("OBJCOPY")
 
     newmode = None
-    if not os.access(file, os.W_OK) or os.access(file, os.R_OK):
+    if not os.access(file, os.R_OK | os.W_OK):
         origmode = os.stat(file)[stat.ST_MODE]
         newmode = origmode | stat.S_IWRITE | stat.S_IREAD
         os.chmod(file, newmode)
@@ -822,7 +822,7 @@  def splitstaticdebuginfo(file, dvar, dv, d):
     dvar = d.getVar('PKGD')
 
     newmode = None
-    if not os.access(file, os.W_OK) or os.access(file, os.R_OK):
+    if not os.access(file, os.R_OK | os.W_OK):
         origmode = os.stat(file)[stat.ST_MODE]
         newmode = origmode | stat.S_IWRITE | stat.S_IREAD
         os.chmod(file, newmode)