Skip to content

Commit

Permalink
refactor(dnsmasq): make signal_dhcp_process const
Browse files Browse the repository at this point in the history
Make the `dhcp_bin_path` parameter to signal_dhcp_process() `const`.

Because we call `basename()` on this value, which may change the input
string, we need to first make a temporary copy of the string into a
buffer.

This fixes the segmentation fault in `test_signal_dhcp_process()`
test on FreeBSD.
  • Loading branch information
aloisklink committed Mar 28, 2023
1 parent f1826ab commit 4a63c6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ task:
cmake --build --preset freebsd --parallel "$(($(sysctl -n hw.ncpu) + 1))"
env:
# list of tests that are currently failing on FreeBSD
FAILING_TESTS: test_edgesec test_dnsmasq test_mdns_service
FAILING_TESTS: test_edgesec test_mdns_service
test_script: |
ctest --preset freebsd --output-on-failure --output-junit junit-test-results.xml \
|| true # We look at junit XML output file for failures
Expand Down
10 changes: 7 additions & 3 deletions src/dhcp/dnsmasq.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,13 @@ int signal_dhcp_process(char *dhcp_bin_path, char *dhcp_conf_path) {
return 0;
}
#else
int signal_dhcp_process(char *dhcp_bin_path) {
os_strlcpy(dnsmasq_proc_name, basename(dhcp_bin_path), MAX_OS_PATH_LEN);

int signal_dhcp_process(const char *dhcp_bin_path) {
{
char dhcp_bin_path_buffer[MAX_OS_PATH_LEN];
os_strlcpy(dhcp_bin_path_buffer, dhcp_bin_path, MAX_OS_PATH_LEN);
os_strlcpy(dnsmasq_proc_name, basename(dhcp_bin_path_buffer),
MAX_OS_PATH_LEN);
}
// Signal any running dnsmasq process to reload the config
if (!signal_process(dnsmasq_proc_name, SIGHUP)) {
log_error("signal_process fail");
Expand Down
2 changes: 1 addition & 1 deletion src/dhcp/dnsmasq.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool kill_dhcp_process(void);
* @param dhcp_bin_path The DHCP server binary path
* @return int 0 on success, -1 on failure
*/
int signal_dhcp_process(char *dhcp_bin_path);
int signal_dhcp_process(const char *dhcp_bin_path);

/**
* @brief Clear the DHCP lease entry for a MAC addrress
Expand Down

0 comments on commit 4a63c6a

Please sign in to comment.