Skip to content

Commit 5ca90f8

Browse files
committed
scripts: add MACHO lazy bindings check to security-check.py
1 parent c897154 commit 5ca90f8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

contrib/devtools/security-check.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,23 @@ def check_MACHO_NX(executable) -> bool:
206206
return False
207207
return True
208208

209+
def check_MACHO_LAZY_BINDINGS(executable) -> bool:
210+
'''
211+
Check for no lazy bindings.
212+
We don't use or check for MH_BINDATLOAD. See #18295.
213+
'''
214+
p = subprocess.Popen([OTOOL_CMD, '-l', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
215+
(stdout, stderr) = p.communicate()
216+
if p.returncode:
217+
raise IOError('Error opening file')
218+
219+
for line in stdout.splitlines():
220+
tokens = line.split()
221+
if 'lazy_bind_off' in tokens or 'lazy_bind_size' in tokens:
222+
if tokens[1] != '0':
223+
return False
224+
return True
225+
209226
CHECKS = {
210227
'ELF': [
211228
('PIE', check_ELF_PIE),
@@ -221,7 +238,8 @@ def check_MACHO_NX(executable) -> bool:
221238
'MACHO': [
222239
('PIE', check_MACHO_PIE),
223240
('NOUNDEFS', check_MACHO_NOUNDEFS),
224-
('NX', check_MACHO_NX)
241+
('NX', check_MACHO_NX),
242+
('LAZY_BINDINGS', check_MACHO_LAZY_BINDINGS)
225243
]
226244
}
227245

0 commit comments

Comments
 (0)