Skip to content

Commit

Permalink
fix: Remove fatal error for non-erroneous case
Browse files Browse the repository at this point in the history
We allow non-null data pointers to be passed to functions
alongside 0-length data. For example when creating a data
buffer that has room for the entire packet, including ignored
header data.

This error broke a rare but legitimate case where we miss
packets during a handshake attempt and need to store empty
handshake packets in the packet array.
  • Loading branch information
JFreegman committed Jan 13, 2024
1 parent 812f931 commit 87bcc43
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a6701e463517907cdb450f3210389633feb6c1cc3a1d3faec48c8b99a4aebf3c /usr/local/bin/tox-bootstrapd
398b0a1ffe8d4d76252964636e083c18ee08e9ceab58b3b377b61821ca04c17c /usr/local/bin/tox-bootstrapd
3 changes: 3 additions & 0 deletions toxcore/group_chats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,9 @@ non_null(1, 2, 3, 5, 6) nullable(4)
static int group_packet_unwrap(const Logger *log, const GC_Connection *gconn, uint8_t *data, uint64_t *message_id,
uint8_t *packet_type, const uint8_t *packet, uint16_t length)
{
assert(data != nullptr);
assert(packet != nullptr);

if (length <= CRYPTO_NONCE_SIZE) {
LOGGER_FATAL(log, "Invalid packet length: %u", length);
return -1;
Expand Down
10 changes: 3 additions & 7 deletions toxcore/group_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,12 @@ static bool create_array_entry(const Logger *log, const Mono_Time *mono_time, GC
}

if (length == 0) {
if (data != nullptr) {
LOGGER_FATAL(log, "Got non-null data with zero length (type %d)", packet_type); // should never happen
return false;
}

array_entry->data = nullptr;
array_entry->data_length = 0;
} else {
if (data == nullptr) {
LOGGER_FATAL(log, "Got null data with non-zero length (type %u)", packet_type); // should never happen
if (data == nullptr) { // should never happen
LOGGER_FATAL(log, "Got null data with non-zero length (length: %u, type %u)",
length, packet_type);
return false;
}

Expand Down

0 comments on commit 87bcc43

Please sign in to comment.