Skip to content

Commit 7622601

Browse files
committed
Fixed memory out of bounds accesses and added more debug options for address sanitizer
1 parent 1c78ca2 commit 7622601

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(njam C)
33

4-
set(NJAM_VERSION "2.0.3")
4+
set(NJAM_VERSION "2.0.4")
55

66
set(CMAKE_C_STANDARD 99)
77
set(CMAKE_C_STANDARD_REQUIRED ON)
@@ -20,12 +20,14 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
2020
# Debug/Release compiler flags
2121
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
2222
add_compile_definitions(DEBUG_MODE=1)
23-
add_compile_options(-g -O0)
23+
add_compile_options(-g -O0 -fsanitize=address -fno-omit-frame-pointer)
24+
add_link_options(-fsanitize=address)
2425
else()
2526
add_compile_definitions(NDEBUG)
2627
add_compile_options(-O3)
2728
endif()
2829

30+
2931
# Executable 1: njam
3032
add_executable(njam
3133
src/main.c

src/network.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ size_t network_count_inactive(const Network network) {
108108
}
109109

110110
size_t counter = 0;
111-
for (size_t i = 0; i <= network.device_count; i++) {
111+
for (size_t i = 0; i < network.device_count; i++) {
112112
if (network.devices[i].status == INACTIVE) {
113113
counter++;
114114
}
@@ -117,14 +117,14 @@ size_t network_count_inactive(const Network network) {
117117
}
118118

119119
void network_set_dead(Network network) {
120-
for (size_t i = 0;i<=network.device_count;i++) {
120+
for (size_t i = 0;i < network.device_count;i++) {
121121
network.devices[i].alive = false;
122122
}
123123
}
124124

125125
size_t network_count_alive_or_jammed(Network network) {
126126
size_t counter = 0;
127-
for (size_t i = 0;i<=network.device_count;i++) {
127+
for (size_t i = 0;i < network.device_count;i++) {
128128
if (network.devices[i].alive || network.devices[i].status == JAMMING || network.devices[i].status == DISCONNECTING) {
129129
counter++;
130130
}
@@ -164,7 +164,7 @@ DeviceGroup print_network_nice(Network network, size_t offset, size_t max_visibl
164164
printf(" %3s %-15s %-17s %-6s %-7s\n", "ID", "IP", "MAC", "Alive", "Jamming");
165165
printf("───────────────────────────────────────────────────────────────\n");
166166

167-
for (size_t i = 0; i <= network.device_count; i++) {
167+
for (size_t i = 0; i < network.device_count; i++) {
168168
if (network.devices[i].alive || network.devices[i].status == JAMMING || network.devices[i].status == DISCONNECTING) {
169169
group.devices[idx++] = &network.devices[i];
170170
}

0 commit comments

Comments
 (0)