Skip to content

Commit 5fdee72

Browse files
authored
Turn on CodeQL and fix BinSkim regressions (#805)
* Turn on CodeQL as requested by DevDiv. * Remove CMake output spew from CMP0135. * Fix BinSkim failures. * clang-format
1 parent 647c890 commit 5fdee72

File tree

7 files changed

+124
-72
lines changed

7 files changed

+124
-72
lines changed

CMakeLists.txt

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ if(NOT CMAKE_MSVC_RUNTIME_LIBRARY)
44
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
55
endif()
66

7+
if(POLICY CMP0135)
8+
cmake_policy(SET CMP0135 NEW)
9+
endif()
10+
711
# ===============
812
# === Options ===
913
# ===============
@@ -34,10 +38,6 @@ if(VCPKG_BUILD_TLS12_DOWNLOADER)
3438
list(APPEND LANGUAGES "C")
3539
endif()
3640

37-
if(VCPKG_DEVELOPMENT_WARNINGS)
38-
set(FMT_PEDANTIC ON CACHE BOOL "")
39-
endif()
40-
4141
if (VCPKG_ARTIFACTS_DEVELOPMENT)
4242
# https://gitlab.kitware.com/cmake/cmake/-/issues/20245
4343
cmake_minimum_required(VERSION 3.17)
@@ -116,10 +116,54 @@ set(CMAKE_CXX_EXTENSIONS OFF)
116116
set(CMAKE_CXX_STANDARD_REQUIRED ON)
117117
set(CMAKE_CXX_STANDARD 17)
118118
if(MSVC)
119-
string(APPEND CMAKE_CXX_FLAGS " /EHsc")
120-
if(CMAKE_BUILD_TYPE STREQUAL "Release")
121-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /guard:cf")
122-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /debugtype:cv,fixup /guard:cf")
119+
# either MSVC, or clang-cl
120+
string(APPEND CMAKE_C_FLAGS " -FC -permissive- -utf-8 /guard:cf")
121+
string(APPEND CMAKE_CXX_FLAGS " /EHsc -FC -permissive- -utf-8 /guard:cf")
122+
string(APPEND CMAKE_C_FLAGS_RELEASE " /Zi")
123+
string(APPEND CMAKE_CXX_FLAGS_RELEASE " /Zi")
124+
125+
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO " /DEBUG /INCREMENTAL:NO /debugtype:cv,fixup /guard:cf")
126+
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE " /DEBUG /INCREMENTAL:NO /debugtype:cv,fixup /guard:cf")
127+
if (MSVC_CXX_ARCHITECTURE_ID STREQUAL "x64")
128+
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO " /CETCOMPAT")
129+
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE " /CETCOMPAT")
130+
endif()
131+
132+
if(VCPKG_DEVELOPMENT_WARNINGS)
133+
string(APPEND CMAKE_C_FLAGS " /W4 /sdl")
134+
string(APPEND CMAKE_CXX_FLAGS " /W4 /sdl")
135+
if(VCPKG_COMPILER STREQUAL "clang")
136+
string(APPEND CMAKE_C_FLAGS " -Wmissing-prototypes -Wno-missing-field-initializers")
137+
string(APPEND CMAKE_CXX_FLAGS " -Wmissing-prototypes -Wno-missing-field-initializers")
138+
else()
139+
# -wd6553 is to workaround a violation in the Windows SDK
140+
# c:\program files (x86)\windows kits\10\include\10.0.22000.0\um\winreg.h(780) : warning C6553: The annotation for function 'RegOpenKeyExW' on _Param_(3) does not apply to a value type.
141+
string(APPEND CMAKE_C_FLAGS " -analyze -analyze:stacksize 39000 -wd6553")
142+
string(APPEND CMAKE_CXX_FLAGS " -analyze -analyze:stacksize 39000 -wd6553")
143+
endif()
144+
endif()
145+
146+
if(VCPKG_WARNINGS_AS_ERRORS)
147+
string(APPEND CMAKE_C_FLAGS " /WX")
148+
string(APPEND CMAKE_CXX_FLAGS " /WX")
149+
endif()
150+
else()
151+
# Neither MSVC nor clang-cl
152+
if(VCPKG_DEVELOPMENT_WARNINGS)
153+
# GCC and clang have different names for the same warning
154+
if(VCPKG_COMPILER STREQUAL "gcc")
155+
set(DECL_WARNING "-Wmissing-declarations")
156+
elseif(VCPKG_COMPILER STREQUAL "clang")
157+
set(DECL_WARNING "-Wmissing-prototypes -Wno-range-loop-analysis")
158+
endif()
159+
160+
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra -Wpedantic -Wno-unknown-pragmas -Wno-missing-field-initializers ${DECL_WARNING}")
161+
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wpedantic -Wno-unknown-pragmas -Wno-missing-field-initializers -Wno-redundant-move ${DECL_WARNING}")
162+
endif()
163+
164+
if(VCPKG_WARNINGS_AS_ERRORS)
165+
string(APPEND CMAKE_C_FLAGS " -Werror")
166+
string(APPEND CMAKE_CXX_FLAGS " -Werror")
123167
endif()
124168
endif()
125169

@@ -143,12 +187,19 @@ include(GNUInstallDirs)
143187
find_package(fmt REQUIRED)
144188
find_package(CMakeRC REQUIRED)
145189

146-
147-
190+
# === Target: locale-resources ===
148191
cmrc_add_resource_library(locale-resources ALIAS cmakerc::locales NAMESPACE cmakerc ${LOCALE_RESOURCES})
149-
150-
151-
192+
if(NOT MSVC)
193+
if(VCPKG_COMPILER STREQUAL "gcc")
194+
target_compile_options(locale-resources PRIVATE
195+
-Wno-missing-declarations
196+
)
197+
elseif(VCPKG_COMPILER STREQUAL "clang")
198+
target_compile_options(locale-resources PRIVATE
199+
-Wno-missing-prototypes
200+
)
201+
endif()
202+
endif()
152203

153204
# === Target: vcpkglib ===
154205

@@ -160,7 +211,6 @@ add_library(vcpkglib OBJECT
160211
)
161212
target_include_directories(vcpkglib PUBLIC include)
162213

163-
vcpkg_target_add_warning_options(vcpkglib)
164214
target_compile_definitions(vcpkglib PUBLIC
165215
VCPKG_VERSION=${VCPKG_VERSION}
166216
VCPKG_BASE_VERSION=${VCPKG_BASE_VERSION}
@@ -354,7 +404,6 @@ add_custom_target(vcpkg-ps1 ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/vcpkg.ps1")
354404
add_executable(vcpkg ${VCPKG_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg.manifest")
355405
target_link_libraries(vcpkg PRIVATE vcpkglib)
356406

357-
vcpkg_target_add_warning_options(vcpkg)
358407
if(VCPKG_ADD_SOURCELINK)
359408
if(VCPKG_VERSION STREQUAL "unknownhash")
360409
message(FATAL_ERROR "Attempted to add source link information, but there was no git SHA defined. VCPKG_ADD_SOURCELINK only works if VCPKG_EMBED_GIT_SHA is set.")
@@ -391,7 +440,6 @@ if (BUILD_TESTING)
391440
if(ANDROID)
392441
target_link_libraries(vcpkg-test PRIVATE log)
393442
endif()
394-
vcpkg_target_add_warning_options(vcpkg-test)
395443

396444
add_test(NAME default COMMAND vcpkg-test --order rand --rng-seed time)
397445

@@ -405,7 +453,6 @@ endif()
405453
if(VCPKG_BUILD_FUZZING)
406454
add_executable(vcpkg-fuzz ${VCPKG_FUZZ_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg.manifest")
407455
target_link_libraries(vcpkg-fuzz PRIVATE vcpkglib)
408-
vcpkg_target_add_warning_options(vcpkg-fuzz)
409456
endif()
410457

411458

azure-pipelines/pipelines.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
variables:
2+
- name: Codeql.Enabled
3+
value: true
14
jobs:
25
- job: linux_gcc_9
36
displayName: 'Ubuntu 20.04 with GCC 9, plus vcpkg-artifacts'
@@ -110,6 +113,8 @@ jobs:
110113
value: $(Build.ArtifactStagingDirectory)\format.diff
111114
- name: 'VCPKG_ROOT'
112115
value: $(Build.SourcesDirectory)\vcpkg-root
116+
- name: Codeql.BuildIdentifier
117+
value: vcpkg_cpp
113118
steps:
114119
- task: Powershell@2
115120
displayName: "Clone vcpkg repo to serve as root"
@@ -120,6 +125,8 @@ jobs:
120125
$sha = (Get-Content vcpkg-init/vcpkg-scripts-sha.txt -Raw).Trim()
121126
git clone https://github.com/microsoft/vcpkg $env:VCPKG_ROOT -n
122127
git -C "$env:VCPKG_ROOT" checkout $sha
128+
- task: CodeQL3000Init@0
129+
displayName: 'CodeQL Initialize'
123130
- task: CmdLine@2
124131
displayName: "Build vcpkg with CMake"
125132
inputs:
@@ -163,3 +170,5 @@ jobs:
163170
inputs:
164171
PathtoPublish: '$(DiffFile)'
165172
ArtifactName: 'format.diff'
173+
- task: CodeQL3000Finalize@0
174+
displayName: 'CodeQL Finalize'

azure-pipelines/signing.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ parameters:
2727
variables:
2828
- name: TeamName
2929
value: vcpkg
30+
- name: Codeql.Enabled
31+
value: true
3032
- group: vcpkg-dependency-source-blobs
3133
- name: FMT_TARBALL_URL
3234
value: "$(fmt-tarball-url)"
@@ -59,9 +61,13 @@ jobs:
5961
- ${{ if ne(parameters.VcpkgBaseVersionOverride, 'default') }}:
6062
- name: VCPKG_INITIAL_BASE_VERSION
6163
value: ${{parameters.VcpkgBaseVersionOverride}}
64+
- name: Codeql.BuildIdentifier
65+
value: vcpkg_ECMAScript
6266
pool:
6367
name: 'VSEngSS-MicroBuild2022-1ES'
6468
steps:
69+
- task: CodeQL3000Init@0
70+
displayName: 'CodeQL Initialize'
6571
- task: Powershell@2
6672
displayName: 'Lock VCPKG_BASE_VERSION'
6773
name: versions
@@ -184,6 +190,8 @@ jobs:
184190
PathtoPublish: '$(Build.ArtifactStagingDirectory)\staging'
185191
ArtifactName: 'staging'
186192
publishLocation: 'Container'
193+
- task: CodeQL3000Finalize@0
194+
displayName: 'CodeQL Finalize'
187195
- job: macos_build
188196
displayName: 'MacOS Build'
189197
dependsOn:
@@ -272,7 +280,10 @@ jobs:
272280
VCPKG_STANDALONE_BUNDLE_SHA: $[ dependencies.arch_independent.outputs['shas.VCPKG_STANDALONE_BUNDLE_SHA'] ]
273281
VCPKG_CE_SHA: $[ dependencies.arch_independent.outputs['shas.VCPKG_CE_SHA'] ]
274282
VCPKG_BASE_VERSION: $[ dependencies.arch_independent.outputs['versions.VCPKG_BASE_VERSION'] ]
283+
Codeql.BuildIdentifier: vcpkg_cpp
275284
steps:
285+
- task: CodeQL3000Init@0
286+
displayName: 'CodeQL Initialize'
276287
- task: CmdLine@2
277288
displayName: "Build vcpkg x86 with CMake"
278289
inputs:
@@ -456,6 +467,8 @@ jobs:
456467
uploadRoslyn: false
457468
uploadTSLint: false
458469
condition: eq(variables['Build.SourceBranchName'], 'main')
470+
- task: CodeQL3000Finalize@0
471+
displayName: 'CodeQL Finalize'
459472
# Publish everything to a Drop
460473
- task: PublishBuildArtifacts@1
461474
displayName: 'Publish Drop'

cmake/FindCMakeRC.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ option(VCPKG_DEPENDENCY_CMAKERC "CMake-based C++ resource compiler" OFF)
66
# with different content.
77
set(VCPKG_CMAKERC_URL "https://github.com/vector-of-bool/cmrc/archive/refs/tags/2.0.1.tar.gz" CACHE STRING "URL to the cmrc release tarball to use.")
88

9+
if(POLICY CMP0135)
10+
cmake_policy(SET CMP0135 NEW)
11+
endif()
12+
913
include(FetchContent)
1014
FetchContent_Declare(
1115
CMakeRC

cmake/Findfmt.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ if(NOT VCPKG_FMT_URL)
1212
set(VCPKG_FMT_URL "https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.tar.gz")
1313
endif()
1414

15+
if(POLICY CMP0135)
16+
cmake_policy(SET CMP0135 NEW)
17+
endif()
18+
19+
set(OLD_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
20+
set(SKIP_WARNINGS OFF)
21+
if(MSVC AND VCPKG_DEVELOPMENT_WARNINGS AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang"))
22+
set(SKIP_WARNINGS ON)
23+
# fmt\core.h(418): warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>: Did you intend to use the bitwise-and (&) operator? If not, consider removing the redundant '<non-zero constant>' and the && operator.
24+
string(APPEND CMAKE_CXX_FLAGS " /wd6239")
25+
# This one is guarded by an assert
26+
# fmt\format-inl.h(327): warning C6385: Reading invalid data from 'pow10_significands'.: Lines: 298, 300, 327
27+
string(APPEND CMAKE_CXX_FLAGS " /wd6385")
28+
# fmt\os.h(377): warning C6326: Potential comparison of a constant with another constant.
29+
string(APPEND CMAKE_CXX_FLAGS " /wd6326")
30+
endif()
31+
1532
include(FetchContent)
1633
FetchContent_Declare(
1734
fmt
@@ -28,3 +45,7 @@ if(VCPKG_DEPENDENCY_EXTERNAL_FMT)
2845
else()
2946
FetchContent_MakeAvailable(fmt)
3047
endif()
48+
49+
if(SKIP_WARNINGS)
50+
set(CMAKE_CXX_FLAGS "${OLD_CXX_FLAGS}")
51+
endif()

cmake/utilities.cmake

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -35,56 +35,6 @@ On CentOS try the following:
3535
endif()
3636
endfunction()
3737

38-
function(vcpkg_target_add_warning_options TARGET)
39-
if(MSVC)
40-
# either MSVC, or clang-cl
41-
target_compile_options(${TARGET} PRIVATE -FC -permissive- -utf-8)
42-
43-
if(VCPKG_DEVELOPMENT_WARNINGS)
44-
target_compile_options(${TARGET} PRIVATE -W4)
45-
if(VCPKG_COMPILER STREQUAL "clang")
46-
target_compile_options(${TARGET} PRIVATE
47-
-Wmissing-prototypes
48-
-Wno-missing-field-initializers
49-
)
50-
else()
51-
# -wd6553 is to workaround a violation in the Windows SDK
52-
# c:\program files (x86)\windows kits\10\include\10.0.22000.0\um\winreg.h(780) : warning C6553: The annotation for function 'RegOpenKeyExW' on _Param_(3) does not apply to a value type.
53-
target_compile_options(${TARGET} PRIVATE -analyze -analyze:stacksize 39000 -wd6553)
54-
endif()
55-
endif()
56-
57-
if(VCPKG_WARNINGS_AS_ERRORS)
58-
target_compile_options(${TARGET} PRIVATE -WX)
59-
endif()
60-
else()
61-
if(VCPKG_DEVELOPMENT_WARNINGS)
62-
target_compile_options(${TARGET} PRIVATE
63-
-Wall -Wextra -Wpedantic
64-
-Wno-unknown-pragmas
65-
-Wno-missing-field-initializers
66-
-Wno-redundant-move
67-
)
68-
69-
# GCC and clang have different names for the same warning
70-
if(VCPKG_COMPILER STREQUAL "gcc")
71-
target_compile_options(${TARGET} PRIVATE
72-
-Wmissing-declarations
73-
)
74-
elseif(VCPKG_COMPILER STREQUAL "clang")
75-
target_compile_options(${TARGET} PRIVATE
76-
-Wmissing-prototypes
77-
-Wno-range-loop-analysis
78-
)
79-
endif()
80-
endif()
81-
82-
if(VCPKG_WARNINGS_AS_ERRORS)
83-
target_compile_options(${TARGET} PRIVATE -Werror)
84-
endif()
85-
endif()
86-
endfunction()
87-
8838
function(vcpkg_target_add_sourcelink target)
8939
cmake_parse_arguments(PARSE_ARGV 1 "arg" "" "REPO;REF" "")
9040
if(DEFINED arg_UNPARSED_ARGUMENTS)

src/tls12-download.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
#pragma warning(push)
2+
// warning C28251: Inconsistent annotation for '_setjmp': this instance has no annotations. See <no file>(0).
3+
#pragma warning(disable : 28251)
4+
// warning C28301: No annotations for first declaration of '__fastfail'. See <no file>(0).
5+
#pragma warning(disable : 28301)
16
#include <Windows.h>
27
#include <process.h>
38
#include <winhttp.h>
49

510
#include <Softpub.h>
11+
#pragma warning(pop)
612

713
/*
814
* This program must be as small as possible, because it is committed in binary form to the
@@ -47,7 +53,7 @@ static void write_message(const HANDLE std_out, const wchar_t* msg)
4753
win32_abort();
4854
}
4955

50-
if (WriteConsoleW(std_out, msg, wchars_to_write, 0, 0))
56+
if (WriteConsoleW(std_out, msg, (DWORD)wchars_to_write, 0, 0))
5157
{
5258
return;
5359
}
@@ -149,7 +155,7 @@ static void __declspec(noreturn) abort_api_failure(const HANDLE std_out, const w
149155
win32_abort();
150156
}
151157

152-
static void set_delete_on_close_flag(const HANDLE std_out, const HANDLE target, BOOL setting)
158+
static void set_delete_on_close_flag(const HANDLE std_out, const HANDLE target, BOOLEAN setting)
153159
{
154160
FILE_DISPOSITION_INFO fdi = {0};
155161
fdi.DeleteFile = setting;
@@ -159,6 +165,11 @@ static void set_delete_on_close_flag(const HANDLE std_out, const HANDLE target,
159165
}
160166
}
161167

168+
// these are sucked out to avoid
169+
// warning C6262: Function uses '98624' bytes of stack. Consider moving some data to heap.
170+
static wchar_t https_proxy_env[32767];
171+
static char buffer[32768];
172+
162173
#ifndef NDEBUG
163174
int main()
164175
#else // ^^^ debug // !debug vvv
@@ -197,7 +208,6 @@ int __stdcall entry()
197208
write_message(std_out, L" -> ");
198209
write_message(std_out, out_file_path);
199210

200-
wchar_t https_proxy_env[32767];
201211
DWORD access_type;
202212
const wchar_t* proxy_setting;
203213
const wchar_t* proxy_bypass_setting;
@@ -238,7 +248,6 @@ int __stdcall entry()
238248
// Setting delete on close before we do anything means the file will get deleted for us if we crash
239249
set_delete_on_close_flag(std_out, out_file, TRUE);
240250

241-
BOOL results = FALSE;
242251
const HINTERNET session = WinHttpOpen(L"tls12-download/1.0", access_type, proxy_setting, proxy_bypass_setting, 0);
243252
if (!session)
244253
{
@@ -320,7 +329,6 @@ int __stdcall entry()
320329
TerminateProcess(GetCurrentProcess(), 2);
321330
}
322331

323-
char buffer[32768];
324332
for (;;)
325333
{
326334
DWORD received_bytes;

0 commit comments

Comments
 (0)