Skip to content

Commit 8da6e60

Browse files
committed
security: fix possible SQLi, memory DoS, data races, and hardening
1 parent 69068bf commit 8da6e60

15 files changed

Lines changed: 666 additions & 449 deletions

CMakeLists.txt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,30 @@ add_compile_definitions(DEV_STAGE=${DEV_STAGE})
1717

1818
message(STATUS "DEV_STAGE is set to ${DEV_STAGE}")
1919

20+
option(UPQ_HARDENING "Enable compile-time hardening flags" ON)
21+
2022
find_package(OpenSSL REQUIRED)
2123
find_package(PostgreSQL REQUIRED)
2224

2325
include(FetchContent)
2426

2527
FetchContent_Declare(
2628
uvent
27-
GIT_REPOSITORY https://github.com/Usub-development/uvent.git
29+
GIT_REPOSITORY https://github.com/Usub-Foundation/uvent.git
2830
GIT_TAG main
2931
OVERRIDE_FIND_PACKAGE
3032
)
3133

3234
FetchContent_Declare(
3335
ureflect
34-
GIT_REPOSITORY https://github.com/Usub-development/ureflect.git
36+
GIT_REPOSITORY https://github.com/Usub-Foundation/ureflect.git
3537
GIT_TAG main
3638
OVERRIDE_FIND_PACKAGE
3739
)
3840

3941
FetchContent_Declare(
4042
ujson
41-
GIT_REPOSITORY https://github.com/Usub-development/ujson.git
43+
GIT_REPOSITORY https://github.com/Usub-Foundation/ujson.git
4244
GIT_TAG main
4345
OVERRIDE_FIND_PACKAGE
4446
)
@@ -75,6 +77,24 @@ if (TARGET PostgreSQL::pq)
7577
target_link_libraries(upq PUBLIC PostgreSQL::pq)
7678
endif()
7779

80+
if (UPQ_HARDENING)
81+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
82+
target_compile_options(upq PRIVATE
83+
-Wall -Wextra -Wpedantic
84+
-Wformat=2 -Wformat-security
85+
-Wcast-qual -Wcast-align
86+
-Wnull-dereference
87+
-fstack-protector-strong
88+
$<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=2>
89+
)
90+
target_link_options(upq PRIVATE
91+
-Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
92+
)
93+
elseif (MSVC)
94+
target_compile_options(upq PRIVATE /W4 /guard:cf /sdl)
95+
endif()
96+
endif()
97+
7898
set_target_properties(upq PROPERTIES
7999
EXPORT_NAME upq
80100
VERSION ${PROJECT_VERSION}
@@ -101,14 +121,14 @@ if (UPQ_BUILD_EXAMPLES)
101121

102122
FetchContent_Declare(
103123
ulog
104-
GIT_REPOSITORY https://github.com/Usub-development/ulog.git
124+
GIT_REPOSITORY https://github.com/Usub-Foundation/ulog.git
105125
GIT_TAG main
106126
OVERRIDE_FIND_PACKAGE
107127
)
108128
FetchContent_Declare(
109129
unet
110-
GIT_REPOSITORY https://github.com/Usub-development/unet.git
111-
GIT_TAG main
130+
GIT_REPOSITORY https://github.com/Usub-Foundation/unet.git
131+
GIT_TAG v0.2.1
112132
OVERRIDE_FIND_PACKAGE
113133
)
114134
FetchContent_MakeAvailable(unet ulog)

examples/docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ services:
44
container_name: pg_local
55
environment:
66
POSTGRES_USER: postgres
7+
# WARNING: example-only password. NEVER use this in production.
8+
# Replace with a value from a .env file or a secrets manager.
79
POSTGRES_PASSWORD: password
810
POSTGRES_DB: postgres
911
ports:

0 commit comments

Comments
 (0)