Skip to content

Commit 43caa75

Browse files
Merge pull request diffblue#667 from NathanJPhillips/security-scanner-support
Security scanner support
2 parents 08487ad + da9fe29 commit 43caa75

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed

scripts/cpplint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ def RepositoryName(self):
11451145
os.path.exists(os.path.join(current_dir, ".hg")) or
11461146
os.path.exists(os.path.join(current_dir, ".svn"))):
11471147
root_dir = current_dir
1148+
break;
11481149
current_dir = os.path.dirname(current_dir)
11491150

11501151
if (os.path.exists(os.path.join(root_dir, ".git")) or

scripts/filter_lint_by_diff.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
print >>sys.stderr, "Usage: filter_lint_by_diff.py diff.patch repository_root_directory < cpplint_warnings.txt"
99
sys.exit(1)
1010

11-
added_lines = set()
1211
repository_root = sys.argv[2]
1312

14-
diff = unidiff.PatchSet.from_filename(sys.argv[1])
15-
for diff_file in diff:
13+
# Create a set of all the files and the specific lines within that file that are in the diff
14+
added_lines = set()
15+
for diff_file in unidiff.PatchSet.from_filename(sys.argv[1]):
1616
filename = diff_file.target_file
1717
# Skip files deleted in the tip (b side of the diff):
1818
if filename == "/dev/null":
@@ -25,11 +25,12 @@
2525
if diff_line.line_type == "+":
2626
added_lines.add((filename, diff_line.target_line_no))
2727

28-
for l in sys.stdin:
29-
bits = l.split(":")
30-
if len(bits) < 3:
28+
# Print the lines that are in the set
29+
for line in sys.stdin:
30+
line_parts = line.split(":")
31+
if len(line_parts) < 3:
3132
continue
32-
filename = os.path.join(repository_root, bits[0])
33-
linenum = int(bits[1])
33+
filename = os.path.join(repository_root, line_parts[0])
34+
linenum = int(line_parts[1])
3435
if (filename, linenum) in added_lines:
35-
sys.stdout.write(l)
36+
sys.stdout.write(line)

scripts/run_lint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
script_folder=`dirname $0`
6-
absolute_repository_root=`readlink -f $script_folder/..`
6+
absolute_repository_root=`git rev-parse --show-toplevel`
77

88
if [[ "$#" -gt 2 ]]
99
then
@@ -20,6 +20,13 @@ then
2020
exit 1
2121
fi
2222

23+
if ! [[ -e $script_folder/filter_lint_by_diff.py ]]
24+
then
25+
echo "Lint filter script could not be found in the $script_folder directory"
26+
echo "Ensure filter_lint_by_diff.py is inside the $script_folder directory then run again"
27+
exit 1
28+
fi
29+
2330
if [[ "$#" -gt 0 ]]
2431
then
2532
git_start=$1
@@ -62,7 +69,7 @@ for file in $diff_files; do
6269

6370
# Run the linting script and filter:
6471
# The errors from the linter go to STDERR so must be redirected to STDOUT
65-
result=`$script_folder/cpplint.py $file 2>&1 | $script_folder/filter_lint_by_diff.py $diff_file $absolute_repository_root`
72+
result=`$script_folder/cpplint.py $file 2>&1 >/dev/null | $script_folder/filter_lint_by_diff.py $diff_file $absolute_repository_root`
6673

6774
# Providing some errors were relevant we print them out
6875
if [ "$result" ]

src/util/file_util.cpp

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Date: January 2012
3737
#include <direct.h>
3838
#include <Shlwapi.h>
3939
#undef NOMINMAX
40+
#include <util/unicode.h>
4041
#define chdir _chdir
4142
#define popen _popen
4243
#define pclose _pclose
@@ -95,42 +96,55 @@ Function: delete_directory
9596
9697
\*******************************************************************/
9798

98-
void delete_directory(const std::string &path)
99-
{
10099
#ifdef _WIN32
101100

102-
std::string pattern=path+"\\*";
103-
101+
void delete_directory_utf16(const std::wstring &path)
102+
{
103+
std::wstring pattern=path + L"\\*";
104104
// NOLINTNEXTLINE(readability/identifiers)
105-
struct _finddata_t info;
106-
107-
intptr_t handle=_findfirst(pattern.c_str(), &info);
108-
109-
if(handle!=-1)
105+
struct _wfinddata_t info;
106+
intptr_t hFile=_wfindfirst(pattern.c_str(), &info);
107+
if(hFile!=-1)
110108
{
111-
unlink(info.name);
112-
113-
while(_findnext(handle, &info)!=-1)
114-
unlink(info.name);
109+
do
110+
{
111+
if(wcscmp(info.name, L".")==0 || wcscmp(info.name, L"..")==0)
112+
continue;
113+
std::wstring sub_path=path+L"\\"+info.name;
114+
if(info.attrib & _A_SUBDIR)
115+
delete_directory_utf16(sub_path);
116+
else
117+
DeleteFileW(sub_path.c_str());
118+
}
119+
while(_wfindnext(hFile, &info)==0);
120+
_findclose(hFile);
121+
RemoveDirectoryW(path.c_str());
115122
}
123+
}
116124

117-
#else
125+
#endif
118126

127+
void delete_directory(const std::string &path)
128+
{
129+
#ifdef _WIN32
130+
delete_directory_utf16(utf8_to_utf16_little_endian(path));
131+
#else
119132
DIR *dir=opendir(path.c_str());
120-
121133
if(dir!=NULL)
122134
{
123135
struct dirent *ent;
124-
125136
while((ent=readdir(dir))!=NULL)
126-
remove((path+"/"+ent->d_name).c_str());
127-
137+
{
138+
std::string sub_path=path+"/"+ent->d_name;
139+
if(ent->d_type==DT_DIR)
140+
delete_directory(sub_path);
141+
else
142+
remove(sub_path.c_str());
143+
}
128144
closedir(dir);
129145
}
130-
131-
#endif
132-
133146
rmdir(path.c_str());
147+
#endif
134148
}
135149

136150
/*******************************************************************\

0 commit comments

Comments
 (0)