g_string_append_len (priv->header->combined, "\r\n", 2);
priv->header->value->len = priv->header->combined->len -
priv->header->name->len - 4;
+ priv->header->value->str = priv->header->combined->str +
+ priv->header->name->len + 2;
DL_APPEND (priv->msg->headers, priv->header);
rspamd_http_check_special_header (conn, priv);
priv->header = g_slice_alloc (sizeof (struct rspamd_http_header));
if (!priv->new_header) {
priv->new_header = TRUE;
- priv->header->name->str = priv->header->combined->str;
- priv->header->name->len = priv->header->combined->len;
g_string_append_len (priv->header->combined, ": ", 2);
- priv->header->value->str = priv->header->combined->str +
- priv->header->combined->len;
+ priv->header->name->str = priv->header->combined->str;
+ priv->header->name->len = priv->header->combined->len - 2;
}
g_string_append_len (priv->header->combined, at, length);
if (priv->header != NULL) {
g_string_append_len (priv->header->combined, "\r\n", 2);
+ priv->header->value->str = priv->header->combined->str +
+ priv->header->name->len + 2;
priv->header->value->len = priv->header->combined->len -
priv->header->name->len - 4;
DL_APPEND (priv->msg->headers, priv->header);
priv->out[0].iov_len = buf->len;
if (encrypted) {
+ gint meth_offset, nonce_offset, mac_offset;
+
ottery_rand_bytes (nonce, sizeof (nonce));
memset (mac, 0, sizeof (mac));
+ meth_offset = buf->len;
- /* Add some used vars */
- meth_pos = buf->str + buf->len;
-
- /* XXX: bad bad bad
- * TODO:
- * XXX:
- * Actually, g_string_append_len can break everything as it may do realloc,
- * hence, we need to store offsets here instead of the direct pointers
- * XXX: fix fix fix
- */
if (conn->type == RSPAMD_HTTP_SERVER) {
g_string_append_len (buf, repbuf, meth_len);
}
meth_len - 1);
g_string_append_c (buf, ' ');
}
- np = buf->str + buf->len;
+
+ nonce_offset = buf->len;
g_string_append_len (buf, nonce, sizeof (nonce));
- mp = buf->str + buf->len;
+ mac_offset = buf->len;
g_string_append_len (buf, mac, sizeof (mac));
+
/* Need to be encrypted */
if (conn->type == RSPAMD_HTTP_SERVER) {
g_string_append (buf, "\r\n\r\n");
else {
g_string_append_len (buf, repbuf, preludelen);
}
+
+ meth_pos = buf->str + meth_offset;
+ np = buf->str + nonce_offset;
+ mp = buf->str + mac_offset;
}