Skip to content

Commit 7eca5bb

Browse files
committed
fix: testing error
1 parent fa4166f commit 7eca5bb

File tree

3 files changed

+75
-76
lines changed

3 files changed

+75
-76
lines changed

.github/workflows/test-ci-windows.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
arch: [x86, x64]
16+
config: [Release, RelWithDebInfo]
1617
runs-on: windows-latest
1718

1819
# For Caching
@@ -39,6 +40,10 @@ jobs:
3940
run: |
4041
echo "APACHE_ROOT=C:\tools\Apache24" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
4142
43+
# Original Make file contain comment build script for ssdeep,
44+
# which is rely on MSYS2, so we need to install MSYS2.
45+
# If it's enabled, it need msys2 library for ssdeep.
46+
4247
# - name: Setup MSYS2
4348
# uses: msys2/setup-msys2@v2
4449
# with:
@@ -103,39 +108,42 @@ jobs:
103108
-A $cmakeArch `
104109
-DWITH_LUA=ON `
105110
-DWITH_YAJL=ON `
106-
-S IIS -B "iis\build-${{ matrix.arch }}"
111+
-S IIS -B "iis\build"
107112
108113
# -DSSDEEP_ROOT="${{ github.workspace }}\ssdeep-install-${{ matrix.arch }}" `
109114
# -DWITH_SSDEEP=ON `
110115

111116
- name: Build IIS Module
112117
shell: pwsh
113118
run: |
114-
cmake --build "iis\build-${{ matrix.arch }}" --config Release
119+
cmake --build "iis\build" --config ${{ matrix.config }}
115120
116121
- name: Upload artifacts
117122
uses: actions/upload-artifact@v4
118123
with:
119-
name: iis-module-${{ matrix.arch }}
120-
path: iis/build-${{ matrix.arch }}/Release/
124+
name: iis-module-${{ matrix.arch }}-${{ matrix.config }}
125+
path: iis/build/${{ matrix.config }}/
121126

122127
package:
123128
needs: build
124129
runs-on: windows-latest
130+
strategy:
131+
matrix:
132+
config: [Release, RelWithDebInfo]
125133
steps:
126134
- name: Checkout code
127135
uses: actions/checkout@v5
128136

129137
- name: Download x64 artifacts
130138
uses: actions/download-artifact@v4
131139
with:
132-
name: iis-module-x64
140+
name: iis-module-x64-${{ matrix.config }}
133141
path: iis/release/amd64/
134142

135143
- name: Download x86 artifacts
136144
uses: actions/download-artifact@v4
137145
with:
138-
name: iis-module-x86
146+
name: iis-module-x86-${{ matrix.config }}
139147
path: iis/release/x86/
140148

141149
- name: Generate MSI files
@@ -150,21 +158,24 @@ jobs:
150158
- name: Upload artifacts
151159
uses: actions/upload-artifact@v4
152160
with:
153-
name: modsecurityiis-installers
161+
name: modsecurityiis-installers-${{ matrix.config }}
154162
path: iis/modsecurityiis.msi
155163

156164
test:
157165
needs: package
158166
runs-on: windows-latest
167+
strategy:
168+
matrix:
169+
config: [Release, RelWithDebInfo]
159170
steps:
160171
- name: Checkout code
161172
uses: actions/checkout@v5
162173

163174
- name: Download MSI files
164175
uses: actions/download-artifact@v4
165176
with:
166-
name: modsecurityiis-installers
167-
path: ${{ github.workspace }}\
177+
name: modsecurityiis-installers-${{ matrix.config }}
178+
path: ${{ github.workspace }}/
168179

169180
- name: Install MSI
170181
shell: pwsh
@@ -318,5 +329,5 @@ jobs:
318329
$goBinPath = Join-Path $env:USERPROFILE "go\bin"
319330
}
320331
321-
& "$goBinPath\go-ftw.exe" run -d $testRuleDir --cloud -e 920380-1 --show-failures-only
332+
& "$goBinPath\go-ftw.exe" run -d $testRuleDir --cloud -e "920100-2$|920100-4$|920100-8$|920100-12$|920272-5$|920290-1$|920620-1$|920380-1$" --show-failures-only
322333

iis/CMakeLists.txt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ endif()
175175
# Compile definitions to match the original Makefile.win
176176
set(MODSECURITY_VERSION_FLAG "VERSION_IIS") # Define the version flag string
177177
target_compile_definitions(${IIS_MODULE_NAME} PRIVATE
178-
WIN32
179-
WINNT
180178
inline=APR_INLINE
181179
AP_DECLARE_STATIC
182180
WITH_CURL
@@ -198,11 +196,11 @@ option(WITH_YAJL "Enable YAJL support" OFF)
198196
if(WITH_YAJL)
199197
# Manually find YAJL if config.cmake is not available (e.g., from vcpkg)
200198
find_path(YAJL_INCLUDE_DIR yajl/yajl_common.h
201-
PATHS "${CMAKE_CURRENT_SOURCE_DIR}/build-${ARCHITECTURE}/vcpkg_installed/${ARCHITECTURE}-windows/include"
199+
PATHS "${CMAKE_CURRENT_SOURCE_DIR}/build/vcpkg_installed/${ARCHITECTURE}-windows/include"
202200
NO_DEFAULT_PATH
203201
)
204202
find_library(YAJL_LIBRARY NAMES yajl
205-
PATHS "${CMAKE_CURRENT_SOURCE_DIR}/build-${ARCHITECTURE}/vcpkg_installed/${ARCHITECTURE}-windows/lib"
203+
PATHS "${CMAKE_CURRENT_SOURCE_DIR}/build/vcpkg_installed/${ARCHITECTURE}-windows/lib"
206204
NO_DEFAULT_PATH
207205
)
208206

@@ -281,17 +279,10 @@ endif()
281279
if(MSVC)
282280
target_compile_options(${IIS_MODULE_NAME} PRIVATE
283281
/nologo
284-
/O2
285282
/W3
286283
/wd4244
287284
/wd4018
288-
/MD
289-
/Zi
290-
)
291-
292-
# Linker options to match the original Makefile.win
293-
set_target_properties(${IIS_MODULE_NAME} PROPERTIES
294-
LINK_FLAGS "/DEBUG /OPT:REF /OPT:ICF"
285+
295286
)
296287
endif()
297288

iis/mymodule.cpp

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#undef inline
1818
#define inline inline
1919

20-
#include "winsock2.h"
21-
2220
// IIS7 Server API header file
2321
#include <Windows.h>
2422
#include <sal.h>
@@ -32,6 +30,8 @@
3230
#include "api.h"
3331
#include "moduleconfig.h"
3432

33+
#include "winsock2.h"
34+
3535

3636
class REQUEST_STORED_CONTEXT : public IHttpStoredContext
3737
{
@@ -90,66 +90,63 @@ class REQUEST_STORED_CONTEXT : public IHttpStoredContext
9090

9191
char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr)
9292
{
93-
if (pAddr == nullptr) {
94-
return apr_pstrdup(pool, "");
95-
}
96-
97-
DWORD addrSize = pAddr->sa_family == AF_INET ? sizeof(SOCKADDR_IN) : sizeof(SOCKADDR_IN6);
98-
auto buf = (char*)apr_palloc(pool, NI_MAXHOST);
99-
if (buf == nullptr) {
100-
return apr_pstrdup(pool, "");
101-
}
102-
buf[0] = '\0';
103-
104-
if (GetNameInfo(pAddr, addrSize, buf, NI_MAXHOST, nullptr, 0, NI_NUMERICHOST) != 0) {
105-
return apr_pstrdup(pool, "");
106-
}
107-
108-
return buf;
93+
const char *format = "%15[0-9.]:%5[0-9]";
94+
char ip[16] = { 0 }; // ip4 addresses have max len 15
95+
char port[6] = { 0 }; // port numbers are 16bit, ie 5 digits max
96+
97+
DWORD len = 50;
98+
char *buf = (char *)apr_palloc(pool, len);
99+
100+
if(buf == NULL)
101+
return "";
102+
103+
buf[0] = 0;
104+
105+
WSAAddressToString(pAddr, sizeof(SOCKADDR), NULL, buf, &len);
106+
107+
// test for IPV4 with port on the end
108+
if (sscanf(buf, format, ip, port) == 2) {
109+
// IPV4 but with port - remove the port
110+
char* input = ":";
111+
char* ipv4 = strtok(buf, input);
112+
return ipv4;
113+
}
114+
115+
return buf;
109116
}
110117

111118
apr_sockaddr_t *CopySockAddr(apr_pool_t *pool, PSOCKADDR pAddr)
112119
{
113-
apr_sockaddr_t *addr = (apr_sockaddr_t *)apr_palloc(pool, sizeof(apr_sockaddr_t));
120+
apr_sockaddr_t *addr = (apr_sockaddr_t *)apr_palloc(pool, sizeof(apr_sockaddr_t));
121+
int adrlen = 16, iplen = 4;
114122

115-
addr->pool = pool;
116-
addr->hostname = "unknown";
117-
addr->servname = addr->hostname;
118-
addr->family = AF_UNSPEC;
119-
addr->addr_str_len = 0;
120-
addr->ipaddr_len = 0;
121-
addr->ipaddr_ptr = nullptr;
122-
addr->salen = 0;
123-
addr->port = 0;
124-
125-
if (pAddr == nullptr) {
126-
return addr;
123+
if(pAddr->sa_family == AF_INET6)
124+
{
125+
adrlen = 46;
126+
iplen = 16;
127127
}
128128

129+
addr->addr_str_len = adrlen;
129130
addr->family = pAddr->sa_family;
130131

131-
if (pAddr->sa_family == AF_INET) {
132-
auto sin = (SOCKADDR_IN *)pAddr;
133-
addr->addr_str_len = INET_ADDRSTRLEN;
134-
addr->ipaddr_len = sizeof(struct in_addr);
135-
addr->ipaddr_ptr = &addr->sa.sin.sin_addr;
136-
addr->sa.sin.sin_family = AF_INET;
137-
addr->sa.sin.sin_port = sin->sin_port; /* keep network byte order */
138-
/* copy address */
139-
memcpy(&addr->sa.sin.sin_addr, &sin->sin_addr, sizeof(struct in_addr));
140-
addr->salen = sizeof(addr->sa);
141-
addr->port = ntohs(sin->sin_port);
142-
} else if (pAddr->sa_family == AF_INET6) {
143-
auto sin6 = (SOCKADDR_IN6 *)pAddr;
144-
addr->addr_str_len = INET6_ADDRSTRLEN;
145-
addr->ipaddr_len = sizeof(struct in6_addr);
146-
addr->ipaddr_ptr = &addr->sa.sin6.sin6_addr;
147-
addr->sa.sin6.sin6_family = AF_INET6;
148-
addr->sa.sin6.sin6_port = sin6->sin6_port;
149-
memcpy(&addr->sa.sin6.sin6_addr, &sin6->sin6_addr, sizeof(struct in6_addr));
150-
addr->salen = sizeof(addr->sa);
151-
addr->port = ntohs(sin6->sin6_port);
152-
}
132+
addr->hostname = "unknown";
133+
#ifdef WIN32
134+
addr->ipaddr_len = sizeof(IN_ADDR);
135+
#else
136+
addr->ipaddr_len = sizeof(struct in_addr);
137+
#endif
138+
addr->ipaddr_ptr = &addr->sa.sin.sin_addr;
139+
addr->pool = pool;
140+
addr->port = 80;
141+
#ifdef WIN32
142+
memcpy(&addr->sa.sin.sin_addr.S_un.S_addr, pAddr->sa_data, iplen);
143+
#else
144+
memcpy(&addr->sa.sin.sin_addr.s_addr, pAddr->sa_data, iplen);
145+
#endif
146+
addr->sa.sin.sin_family = pAddr->sa_family;
147+
addr->sa.sin.sin_port = 80;
148+
addr->salen = sizeof(addr->sa);
149+
addr->servname = addr->hostname;
153150

154151
return addr;
155152
}
@@ -1324,4 +1321,4 @@ BOOL CMyHttpModule::WriteEventViewerLog(LPCSTR szNotification, WORD category)
13241321
NULL, 1, 0, &szNotification, NULL );
13251322
}
13261323
return FALSE;
1327-
}
1324+
}

0 commit comments

Comments
 (0)