From f6db77da4439334b276f20d6ff7ed64d301d67ef Mon Sep 17 00:00:00 2001 From: Weiqi Wang Date: Thu, 24 Jun 2021 20:38:57 +0800 Subject: [PATCH] sip/transp: add essential fields check (#119) --- src/sip/transp.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/sip/transp.c b/src/sip/transp.c index cc7d88daf..0567cf7df 100644 --- a/src/sip/transp.c +++ b/src/sip/transp.c @@ -279,6 +279,18 @@ static void conn_keepalive_handler(void *arg) conn_keepalive_handler, conn); } +static bool have_essential_fields(const struct sip_msg *msg) +{ + if (pl_isset(&(msg->to.auri)) && + pl_isset(&(msg->from.auri)) && + pl_isset(&(msg->cseq.met)) && + pl_isset(&(msg->callid)) && + pl_isset(&(msg->maxfwd)) && + pl_isset(&(msg->via.branch))) + return true; + + return false; +} static void sip_recv(struct sip *sip, const struct sip_msg *msg, size_t start) @@ -291,6 +303,13 @@ static void sip_recv(struct sip *sip, const struct sip_msg *msg, sip->arg); } + if (msg->req) { + if (!have_essential_fields(msg)){ + (void)sip_reply(sip, msg, 400, "Bad Request"); + return; + } + } + while (le) { struct sip_lsnr *lsnr = le->data;