gyptest-cl-buffer-security-check.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # Copyright (c) 2012 Google Inc. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """
  6. Make sure buffer security check setting is extracted properly.
  7. """
  8. import TestGyp
  9. import sys
  10. if sys.platform == 'win32':
  11. test = TestGyp.TestGyp(formats=['msvs', 'ninja'])
  12. CHDIR = 'compiler-flags'
  13. test.run_gyp('buffer-security-check.gyp', chdir=CHDIR)
  14. test.build('buffer-security-check.gyp', chdir=CHDIR)
  15. def GetDisassemblyOfMain(exe):
  16. # The standard library uses buffer security checks independent of our
  17. # buffer security settings, so we extract just our code (i.e. main()) to
  18. # check against.
  19. full_path = test.built_file_path(exe, chdir=CHDIR)
  20. output = test.run_dumpbin('/disasm', full_path)
  21. result = []
  22. in_main = False
  23. for line in output.splitlines():
  24. if line == '_main:':
  25. in_main = True
  26. elif in_main:
  27. # Disassembly of next function starts.
  28. if line.startswith('_'):
  29. break
  30. result.append(line)
  31. return '\n'.join(result)
  32. # Buffer security checks are on by default, make sure security_cookie
  33. # appears in the disassembly of our code.
  34. if 'security_cookie' not in GetDisassemblyOfMain('test_bsc_unset.exe'):
  35. test.fail_test()
  36. # Explicitly on.
  37. if 'security_cookie' not in GetDisassemblyOfMain('test_bsc_on.exe'):
  38. test.fail_test()
  39. # Explicitly off, shouldn't be a reference to the security cookie.
  40. if 'security_cookie' in GetDisassemblyOfMain('test_bsc_off.exe'):
  41. test.fail_test()
  42. test.pass_test()