~ubuntu-branches/ubuntu/precise/enigmail/precise-security

« back to all changes in this revision

Viewing changes to build/win32/autobinscope.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-11-12 16:36:01 UTC
  • mfrom: (0.12.15)
  • Revision ID: package-import@ubuntu.com-20121112163601-t8e8skdfi3ni9iqp
Tags: 2:1.4.6-0ubuntu0.12.04.1
* New upstream release v1.4.6
  - see LP: #1080212 for USN information
* Drop unneeded patches
  - remove debian/patches/correct-version-number.diff
  - remove debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Support building in an objdir
  - update debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
# ***** BEGIN LICENSE BLOCK *****
4
 
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
 
#
6
 
# The contents of this file are subject to the Mozilla Public License Version
7
 
# 1.1 (the "License"); you may not use this file except in compliance with
8
 
# the License. You may obtain a copy of the License at
9
 
# http://www.mozilla.org/MPL/
10
 
#
11
 
# Software distributed under the License is distributed on an "AS IS" basis,
12
 
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
 
# for the specific language governing rights and limitations under the
14
 
# License.
15
 
#
16
 
# The Original Code is mozilla.org code.
17
 
#
18
 
# The Initial Developer of the Original Code is
19
 
# the Mozilla Foundation.
20
 
# Portions created by the Initial Developer are Copyright (C) 2011
21
 
# the Initial Developer. All Rights Reserved.
22
 
#
23
 
# Contributor(s):
24
 
#   imelven@mozilla.com
25
 
#
26
 
# Alternatively, the contents of this file may be used under the terms of
27
 
# either the GNU General Public License Version 2 or later (the "GPL"), or
28
 
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
 
# in which case the provisions of the GPL or the LGPL are applicable instead
30
 
# of those above. If you wish to allow use of your version of this file only
31
 
# under the terms of either the GPL or the LGPL, and not to allow others to
32
 
# use your version of this file under the terms of the MPL, indicate your
33
 
# decision by deleting the provisions above and replace them with the notice
34
 
# and other provisions required by the GPL or the LGPL. If you do not delete
35
 
# the provisions above, a recipient may use your version of this file under
36
 
# the terms of any one of the MPL, the GPL or the LGPL.
37
 
#
38
 
# ***** END LICENSE BLOCK *****
39
 
 
40
 
# run Microsoft's Binscope tool (http://www.microsoft.com/download/en/details.aspx?id=11910)
41
 
# against a fresh Windows build. output a 'binscope.log' file with full details
42
 
# of the run and appropriate strings to integrate with the buildbots
43
 
 
44
 
# from the docs : "The error code returned when running under the command line is equal 
45
 
# to the number of failures the tool reported plus the number of errors. BinScope will return 
46
 
# 0 only if there are no errors or failures."
47
 
 
48
 
# the symbol dir should point to the symbol dir hierarchy created
49
 
# via running make buildsymbols in a windows build's objdir
50
 
 
51
 
import sys
52
 
import subprocess
53
 
import os
54
 
 
55
 
BINSCOPE_OUTPUT_LOGFILE = r".\binscope_xml_output.log"
56
 
 
57
 
# usage
58
 
if len(sys.argv) < 3:
59
 
  print """usage : autobinscope.by path_to_binary path_to_symbols [log_file_path]"
60
 
                log_file_path is optional, log will be written to .\binscope_xml_output.log by default"""
61
 
  sys.exit(0)
62
 
 
63
 
binary_path = sys.argv[1]
64
 
symbol_path = sys.argv[2]
65
 
 
66
 
if len(sys.argv) == 4:
67
 
  log_file_path = sys.argv[3]
68
 
else:
69
 
  log_file_path = BINSCOPE_OUTPUT_LOGFILE
70
 
  
71
 
# execute binscope against the binary, using the BINSCOPE environment
72
 
# variable as the path to binscope.exe
73
 
try:
74
 
  binscope_path = os.environ['BINSCOPE']
75
 
except KeyError:
76
 
  print "BINSCOPE environment variable is not set, can't check DEP/ASLR etc. status."
77
 
  sys.exit(0)
78
 
  
79
 
try:    
80
 
  proc = subprocess.Popen([binscope_path, "/target", binary_path,
81
 
    "/output", log_file_path, "/sympath", symbol_path,
82
 
    "/c", "ATLVersionCheck", "/c", "ATLVulnCheck", "/c", "FunctionPointersCheck",
83
 
    "/c", "SharedSectionCheck", "/c", "APTCACheck", "/c", "NXCheck",
84
 
    "/c", "GSCheck", "/c", "GSFunctionSafeBuffersCheck", "/c", "GSFriendlyInitCheck",
85
 
    "/c", "CompilerVersionCheck", "/c", "SafeSEHCheck", "/c", "SNCheck",
86
 
    "/c", "DBCheck"], stdout=subprocess.PIPE)
87
 
 
88
 
except WindowsError, (errno, strerror): 
89
 
  if errno != 2 and errno != 3:
90
 
    print "Unexpected error ! \nError " + str(errno) + " : " + strerror + "\nExiting !\n"
91
 
    sys.exit(0)
92
 
  else:
93
 
    print "Could not locate binscope at location : %s\n" % binscope_path
94
 
    print "Binscope wasn't installed or the BINSCOPE env variable wasn't set correctly, skipping this check and exiting..."
95
 
    sys.exit(0)
96
 
 
97
 
proc.wait()
98
 
 
99
 
output = proc.communicate()[0]
100
 
 
101
 
# is this a PASS or a FAIL ? 
102
 
if proc.returncode != 0:
103
 
  print "TEST-UNEXPECTED-FAIL | autobinscope.py | %s is missing a needed Windows protection, such as /GS or ASLR" % binary_path
104
 
else:
105
 
  print "TEST-PASS | autobinscope.py | %s succeeded" % binary_path
106
 
 
107
 
 
108
 
 
 
1
#!/usr/bin/env python
 
2
 
 
3
# This Source Code Form is subject to the terms of the Mozilla Public
 
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
 
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
6
 
 
7
# run Microsoft's Binscope tool (http://www.microsoft.com/download/en/details.aspx?id=11910)
 
8
# against a fresh Windows build. output a 'binscope.log' file with full details
 
9
# of the run and appropriate strings to integrate with the buildbots
 
10
 
 
11
# from the docs : "The error code returned when running under the command line is equal 
 
12
# to the number of failures the tool reported plus the number of errors. BinScope will return 
 
13
# 0 only if there are no errors or failures."
 
14
 
 
15
# the symbol dir should point to the symbol dir hierarchy created
 
16
# via running make buildsymbols in a windows build's objdir
 
17
 
 
18
import sys
 
19
import subprocess
 
20
import os
 
21
 
 
22
BINSCOPE_OUTPUT_LOGFILE = r".\binscope_xml_output.log"
 
23
 
 
24
# usage
 
25
if len(sys.argv) < 3:
 
26
  print """usage : autobinscope.by path_to_binary path_to_symbols [log_file_path]"
 
27
                log_file_path is optional, log will be written to .\binscope_xml_output.log by default"""
 
28
  sys.exit(0)
 
29
 
 
30
binary_path = sys.argv[1]
 
31
symbol_path = sys.argv[2]
 
32
 
 
33
if len(sys.argv) == 4:
 
34
  log_file_path = sys.argv[3]
 
35
else:
 
36
  log_file_path = BINSCOPE_OUTPUT_LOGFILE
 
37
  
 
38
# execute binscope against the binary, using the BINSCOPE environment
 
39
# variable as the path to binscope.exe
 
40
try:
 
41
  binscope_path = os.environ['BINSCOPE']
 
42
except KeyError:
 
43
  print "BINSCOPE environment variable is not set, can't check DEP/ASLR etc. status."
 
44
  sys.exit(0)
 
45
  
 
46
try:    
 
47
  proc = subprocess.Popen([binscope_path, "/target", binary_path,
 
48
    "/output", log_file_path, "/sympath", symbol_path,
 
49
    "/c", "ATLVersionCheck", "/c", "ATLVulnCheck", "/c", "FunctionPointersCheck",
 
50
    "/c", "SharedSectionCheck", "/c", "APTCACheck", "/c", "NXCheck",
 
51
    "/c", "GSCheck", "/c", "GSFunctionSafeBuffersCheck", "/c", "GSFriendlyInitCheck",
 
52
    "/c", "CompilerVersionCheck", "/c", "SafeSEHCheck", "/c", "SNCheck",
 
53
    "/c", "DBCheck"], stdout=subprocess.PIPE)
 
54
 
 
55
except WindowsError, (errno, strerror): 
 
56
  if errno != 2 and errno != 3:
 
57
    print "Unexpected error ! \nError " + str(errno) + " : " + strerror + "\nExiting !\n"
 
58
    sys.exit(0)
 
59
  else:
 
60
    print "Could not locate binscope at location : %s\n" % binscope_path
 
61
    print "Binscope wasn't installed or the BINSCOPE env variable wasn't set correctly, skipping this check and exiting..."
 
62
    sys.exit(0)
 
63
 
 
64
proc.wait()
 
65
 
 
66
output = proc.communicate()[0]
 
67
 
 
68
# is this a PASS or a FAIL ? 
 
69
if proc.returncode != 0:
 
70
  print "Error count: %d" % proc.returncode
 
71
  print "TEST-UNEXPECTED-FAIL | autobinscope.py | %s is missing a needed Windows protection, such as /GS or ASLR" % binary_path
 
72
  logfile = open(log_file_path, "r")
 
73
  for line in logfile:
 
74
    print(line),
 
75
else:
 
76
  print "TEST-PASS | autobinscope.py | %s succeeded" % binary_path