Skip to content

Commit 87bcc43

Browse files
committed
fix: Remove fatal error for non-erroneous case
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.
1 parent 812f931 commit 87bcc43

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a6701e463517907cdb450f3210389633feb6c1cc3a1d3faec48c8b99a4aebf3c /usr/local/bin/tox-bootstrapd
1+
398b0a1ffe8d4d76252964636e083c18ee08e9ceab58b3b377b61821ca04c17c /usr/local/bin/tox-bootstrapd

toxcore/group_chats.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,9 @@ non_null(1, 2, 3, 5, 6) nullable(4)
14421442
static int group_packet_unwrap(const Logger *log, const GC_Connection *gconn, uint8_t *data, uint64_t *message_id,
14431443
uint8_t *packet_type, const uint8_t *packet, uint16_t length)
14441444
{
1445+
assert(data != nullptr);
1446+
assert(packet != nullptr);
1447+
14451448
if (length <= CRYPTO_NONCE_SIZE) {
14461449
LOGGER_FATAL(log, "Invalid packet length: %u", length);
14471450
return -1;

toxcore/group_connection.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,12 @@ static bool create_array_entry(const Logger *log, const Mono_Time *mono_time, GC
101101
}
102102

103103
if (length == 0) {
104-
if (data != nullptr) {
105-
LOGGER_FATAL(log, "Got non-null data with zero length (type %d)", packet_type); // should never happen
106-
return false;
107-
}
108-
109104
array_entry->data = nullptr;
110105
array_entry->data_length = 0;
111106
} else {
112-
if (data == nullptr) {
113-
LOGGER_FATAL(log, "Got null data with non-zero length (type %u)", packet_type); // should never happen
107+
if (data == nullptr) { // should never happen
108+
LOGGER_FATAL(log, "Got null data with non-zero length (length: %u, type %u)",
109+
length, packet_type);
114110
return false;
115111
}
116112

0 commit comments

Comments
 (0)