Skip to content

Commit

Permalink
Merge pull request #39 from paullouisageneau/no-null-buffer-sento
Browse files Browse the repository at this point in the history
Prevent passing NULL buffer to sendto() for better compatibility with C standard libraries
  • Loading branch information
paullouisageneau authored Sep 3, 2024
2 parents 86fdc01 + c2ff58c commit fb4c74e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/pcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ int pcp_interrupt(protocol_state_t *state, bool hard) {
PLUM_LOG_VERBOSE("Interrupting PCP/NAT-PMP operation");
atomic_store(&impl->interrupt, hard ? PCP_INTERRUPT_HARD : PCP_INTERRUPT_SOFT);

if (udp_sendto_self(impl->sock, NULL, 0) < 0) {
char dummy = 0; // Some C libraries might error out on NULL pointers
if (udp_sendto_self(impl->sock, &dummy, 0) < 0) {
if (sockerrno != SEAGAIN && sockerrno != SEWOULDBLOCK) {
PLUM_LOG_WARN(
"Failed to interrupt PCP/NAT-PMP operation by triggering socket, errno=%d",
Expand Down
3 changes: 2 additions & 1 deletion src/upnp.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ int upnp_interrupt(protocol_state_t *state, bool hard) {
PLUM_LOG_VERBOSE("Interrupting UPnP operation");
atomic_store(&impl->interrupt, hard ? UPNP_INTERRUPT_HARD : UPNP_INTERRUPT_SOFT);

if (udp_sendto_self(impl->sock, NULL, 0) < 0) {
char dummy = 0; // Some C libraries might error out on NULL pointers
if (udp_sendto_self(impl->sock, &dummy, 0) < 0) {
if (sockerrno != SEAGAIN && sockerrno != SEWOULDBLOCK) {
PLUM_LOG_WARN("Failed to interrupt UPnP operation by triggering socket, errno=%d",
sockerrno);
Expand Down

0 comments on commit fb4c74e

Please sign in to comment.