From: Sean Bright Date: Fri, 10 Jan 2020 20:43:24 +0000 (-0500) Subject: res_pjsip_notify: Only allow a single Event header to be added to a NOTIFY X-Git-Tag: 13.31.0-rc1~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6648472a284b4b85e9f9585ba2739e897ed0e98d;p=thirdparty%2Fasterisk.git res_pjsip_notify: Only allow a single Event header to be added to a NOTIFY ASTERISK-27775 #close Reported by: AvayaXAsterisk Change-Id: Iad158e908e34675ad98f74d09c5e73024e50c257 --- diff --git a/res/res_pjsip_notify.c b/res/res_pjsip_notify.c index a424eaa464..4366e566db 100644 --- a/res/res_pjsip_notify.c +++ b/res/res_pjsip_notify.c @@ -511,6 +511,16 @@ static int not_allowed(const char *name) return 0; } +/*! + * \internal + * \brief Check if the given header can be added to a message more than once. + */ +static int multiple_headers_allowed(const char *name) +{ + /* This can be extended to include additional headers */ + return strcasecmp("Event", name); +} + /*! * \internal * \brief If a content type was specified add it and the content body to the @@ -564,6 +574,18 @@ static void build_notify(pjsip_tx_data *tdata, const char *name, const char *val } ast_str_append(content, 0, "%s", value); } else { + /* See if there is an existing one */ + if (!multiple_headers_allowed(name)) { + pj_str_t hdr_name; + pj_cstr(&hdr_name, name); + + if (pjsip_msg_find_hdr_by_name(tdata->msg, &hdr_name, NULL)) { + ast_log(LOG_ERROR, "Only one '%s' header can be added to a NOTIFY, " + "ignoring \"%s: %s\"\n", name, name, value); + return; + } + } + ast_sip_add_header(tdata, name, value); } }