Skip to content

Commit c5c9921

Browse files
Fix CodeQL security issues (#7985)
This path fixes 7 issues raised by codeql: - `dxcapi.use.h` - [SM01925] Uncontrolled process operation: Add comment, so the scan can ignore this issue. - `ProgramTest.cpp` - [SM01932] User-controlled data may not be null terminated: Add comment, so the scan can ignore this issue. - `DxbcConverter.cpp` - [SM01928] Comparison of narrow type with wide type in loop condition: Change affected variable to be `unsigned` instead of `BYTE`. - `ExecutionTest.cpp` - [SM01733] Too few arguments to formatting function: Remove an argument that didn't seem to be used. - `DxbcUtil.cpp` - [SM01928] Comparison of narrow type with wide type in loop condition: Cast the result of `+` operator back to BYTE, since it was implicit being cast to an int. - `DSAclean.py` - [SM03905] Inefficient regular expression: Script doesn't seem to be used anymore, so it is being removed. - `CaptureCmd` - [SM02167] Weak hashes : Script doesn't seem to be used anymore, so it is being removed. --------- Co-authored-by: Joao Saffran <[email protected]>
1 parent c8a39c7 commit c5c9921

File tree

7 files changed

+14
-112
lines changed

7 files changed

+14
-112
lines changed

include/dxc/Support/dxcapi.use.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class SpecificDllLoader : public DllLoader {
6969
return S_OK;
7070

7171
#ifdef _WIN32
72-
m_dll = LoadLibraryA(dllName);
72+
m_dll = LoadLibraryA(
73+
dllName); // CodeQL [SM01925] This is by design, intended to be used to
74+
// test multiple validators versions.
7375
if (m_dll == nullptr)
7476
return HRESULT_FROM_WIN32(GetLastError());
7577
m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName);
@@ -81,7 +83,9 @@ class SpecificDllLoader : public DllLoader {
8183
return hr;
8284
}
8385
#else
84-
m_dll = ::dlopen(dllName, RTLD_LAZY);
86+
m_dll = ::dlopen(
87+
dllName, RTLD_LAZY); // CodeQL [SM01925] This is by design, intended to
88+
// be used to test multiple validators versions.
8589
if (m_dll == nullptr)
8690
return E_FAIL;
8791
m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName);

projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,8 +6393,8 @@ void DxbcConverter::EmitGSOutputRegisterStore(unsigned StreamId) {
63936393
CompType DxbcValueType = SE.GetCompType();
63946394
Type *pDxbcValueType = DxbcValueType.GetLLVMType(m_Ctx);
63956395

6396-
for (BYTE c = 0; c < SE.GetCols(); c++) {
6397-
BYTE Comp = SE.GetStartCol() + c;
6396+
for (unsigned c = 0; c < SE.GetCols(); c++) {
6397+
unsigned Comp = SE.GetStartCol() + c;
63986398

63996399
Value *pValue;
64006400
// 1. Load value from the corresponding temp reg.

projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/IR/LLVMContext.h"
1818
#include "llvm/IR/Type.h"
1919
#include "llvm/Support/Casting.h"
20+
#include <cassert>
2021

2122
#include "DxbcUtil.h"
2223
#include "Support/DXIncludes.h"
@@ -46,7 +47,8 @@ CMask::CMask(BYTE StartComp, BYTE NumComp) {
4647
(StartComp + NumComp - 1) < DXBC::kAllCompMask,
4748
"otherwise the caller did not check");
4849
m_Mask = 0;
49-
for (BYTE c = StartComp; c < StartComp + NumComp; c++) {
50+
BYTE EndComp = StartComp + NumComp;
51+
for (BYTE c = StartComp; c < EndComp; c++) {
5052
m_Mask |= (1 << c);
5153
}
5254
}

tools/clang/unittests/HLSLExec/ExecutionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2451,7 +2451,7 @@ TEST_F(ExecutionTest, WaveIntrinsicsTest) {
24512451
}
24522452

24532453
// Waves should cover 4 threads or more.
2454-
LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
2454+
LogCommentFmt(L"Found %u distinct lane ids", firstLaneIds.size());
24552455
if (!dxbc) {
24562456
VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
24572457
}

tools/clang/utils/CaptureCmd

Lines changed: 0 additions & 73 deletions
This file was deleted.

unittests/Support/ProgramTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ TEST(ProgramTest, TestWriteWithSystemEncoding) {
313313
#else
314314
char buf[10];
315315
ASSERT_EQ(::read(fd, buf, 10), 10);
316-
ASSERT_EQ(strncmp(buf, utf8_text, 10), 0);
316+
ASSERT_EQ(strncmp(buf, utf8_text, 10),
317+
0); // CodeQL [SM01932] the file content is controlled by the test.
317318
#endif
318319
::close(fd);
319320
ASSERT_NO_ERROR(fs::remove(file_pathname.str()));

utils/DSAclean.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)