summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2018-12-25 22:23:08 +0100
committerdequis <dx@dxzone.com.ar>2018-12-26 00:25:42 +0100
commit4fb29aabac3c78d88a99bbcd3396fc91e33f597a (patch)
treef64bf70612d0876b67196032fe22a75ab983457d
parent7dbd24d7e29c421701b43d8e8a4ffc5c9e1ecbf5 (diff)
downloadbitlbee-facebook-4fb29aabac3c78d88a99bbcd3396fc91e33f597a.tar.gz
Fix "Failed to read fixed header" with TLS 1.3
Ported from a march 2018 commit in purple-facebook, which is when NSS updated to TLS 1.3, and purple often uses NSS. Now it's happening with gnutls 3.6, and bitlbee often uses gnutls. The code is slightly different because bitlbee has ssl_pending(). Unfortunately, I wasn't able to test this, because even with that version it works for me. Who knows. Maybe this doesn't fix anything at all.
-rw-r--r--facebook/facebook-mqtt.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/facebook/facebook-mqtt.c b/facebook/facebook-mqtt.c
index 9610bbd..cc51a25 100644
--- a/facebook/facebook-mqtt.c
+++ b/facebook/facebook-mqtt.c
@@ -340,26 +340,33 @@ fb_mqtt_cb_read(gpointer data, gint fd, b_input_condition cond)
g_byte_array_set_size(priv->rbuf, 0);
res = ssl_read(priv->ssl, (gchar *) &byte, sizeof byte);
- g_byte_array_append(priv->rbuf, &byte, sizeof byte);
- if (res != sizeof byte) {
+ if (res < 0 && ssl_pending(priv->ssl)) {
+ return TRUE;
+ } else if (res != 1) {
fb_mqtt_error(mqtt, FB_MQTT_ERROR_GENERAL,
"Failed to read fixed header");
return FALSE;
}
+ g_byte_array_append(priv->rbuf, &byte, sizeof byte);
+
mult = 1;
do {
res = ssl_read(priv->ssl, (gchar *) &byte, sizeof byte);
- g_byte_array_append(priv->rbuf, &byte, sizeof byte);
- if (res != sizeof byte) {
+ /* TODO: this case isn't handled yet */
+ if (0 && res < 0 && ssl_pending(priv->ssl)) {
+ return TRUE;
+ } else if (res != 1) {
fb_mqtt_error(mqtt, FB_MQTT_ERROR_GENERAL,
"Failed to read packet size");
return FALSE;
}
+ g_byte_array_append(priv->rbuf, &byte, sizeof byte);
+
priv->remz += (byte & 127) * mult;
mult *= 128;
} while ((byte & 128) != 0);
@@ -369,7 +376,9 @@ fb_mqtt_cb_read(gpointer data, gint fd, b_input_condition cond)
size = MIN(priv->remz, sizeof buf);
rize = ssl_read(priv->ssl, (gchar *) buf, size);
- if (rize < 1) {
+ if (rize < 0 && ssl_pending(priv->ssl)) {
+ return TRUE;
+ } else if (rize < 1) {
fb_mqtt_error(mqtt, FB_MQTT_ERROR_GENERAL,
"Failed to read packet data");
return FALSE;