From c3d0b95a58695257cc40cbc9a51dfa6c7f172ec4 Mon Sep 17 00:00:00 2001 From: Jonathan Perkin Date: Wed, 11 Dec 2019 12:06:23 +0000 Subject: [PATCH] dependencies: Fix executable file test on Unix. access(2) tests for X_OK that return true do not always guarantee that the file is executable. Instead check the stat(2) mode bits explicitly. This fixes any builds or installs executed as root on Solaris and illumos that contain non-executable scripts. --- mesonbuild/dependencies/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 2abd243ca..9170400ec 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -21,6 +21,7 @@ import re import json import shlex import shutil +import stat import textwrap import platform from typing import Any, Dict, List, Optional, Tuple, Type, Union @@ -1859,10 +1860,11 @@ class ExternalProgram: def _is_executable(self, path): suffix = os.path.splitext(path)[-1].lower()[1:] + execmask = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH if mesonlib.is_windows(): if suffix in self.windows_exts: return True - elif os.access(path, os.X_OK): + elif os.stat(path).st_mode & execmask: return not os.path.isdir(path) return False