From: Liviu Chircu <liviu@opensips.org>
Date: Thu, 15 Feb 2018 19:00:52 +0200
Subject: [PATCH] rest_client: Fix a string handling bug in append_hf()
Issue reported by Pasan Meemaduma
(cherry picked from commit 888d5e9b3f99423288a20065a2b90d28a9bb030e)
diff --git a/modules/rest_client/rest_methods.c b/modules/rest_client/rest_methods.c
index d73da25ce..cfdcfc827 100644
--- a/modules/rest_client/rest_methods.c
+++ b/modules/rest_client/rest_methods.c
@@ -1070,7 +1070,7 @@ int rest_append_hf_method(struct sip_msg *msg, str *hfv)
{
char buf[MAX_HEADER_FIELD_LEN];
- if (hfv->len > MAX_HEADER_FIELD_LEN) {
+ if (hfv->len + 1 > MAX_HEADER_FIELD_LEN) {
LM_ERR("header field buffer too small\n");
return -1;
}
@@ -1079,6 +1079,7 @@ int rest_append_hf_method(struct sip_msg *msg, str *hfv)
/* append the header to the global list */
strncpy(buf, hfv->s, hfv->len);
+ buf[hfv->len] = '\0';
header_list = curl_slist_append(header_list, buf);
return 1;