Discussion:
[sr-dev] git:master:260a825a: core: parser/parse_hname2 - option to skip printing logs on parse failure
Daniel-Constantin Mierla
2021-06-02 16:07:57 UTC
Permalink
Content preview: Module: kamailio Branch: master Commit: 260a825a48ac6f8b845a4b934f86ea3e04c120d4
URL: https://github.com/kamailio/kamailio/commit/260a825a48ac6f8b845a4b934f86ea3e04c120d4
Author: Daniel-Constantin Mierla <***@gmail.com> Committer: Daniel-Constantin
Mierla <***@gmail.com> Date: 2021-06-02T18:00:35+02:00

Content analysis details: (-2.4 points, 5.5 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP
-1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1%
[score: 0.0000]
0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is
CUSTOM_MED
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
provider (miconda[at]gmail.com)
0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level
mail domains are different
1.0 FORGED_GMAIL_RCVD 'From' gmail.com does not match 'Received'
headers
0.2 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and
EnvelopeFrom freemail headers are
different
-1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list
manager

Module: kamailio
Branch: master
Commit: 260a825a48ac6f8b845a4b934f86ea3e04c120d4
URL: https://github.com/kamailio/kamailio/commit/260a825a48ac6f8b845a4b934f86ea3e04c120d4

Author: Daniel-Constantin Mierla <***@gmail.com>
Committer: Daniel-Constantin Mierla <***@gmail.com>
Date: 2021-06-02T18:00:35+02:00

core: parser/parse_hname2 - option to skip printing logs on parse failure

---

Modified: src/core/parser/parse_hname2.c
Modified: src/core/parser/parse_hname2.h

---

Diff: https://github.com/kamailio/kamailio/commit/260a825a48ac6f8b845a4b934f86ea3e04c120d4.diff
Patch: https://github.com/kamailio/kamailio/commit/260a825a48ac6f8b845a4b934f86ea3e04c120d4.patch

---

diff --git a/src/core/parser/parse_hname2.c b/src/core/parser/parse_hname2.c
index ab56fa4ea5..20398a9595 100644
--- a/src/core/parser/parse_hname2.c
+++ b/src/core/parser/parse_hname2.c
@@ -219,21 +219,25 @@ int ksr_hname_init_config(void)
* - fills hdr structure (must not be null)
* - set hdr->type=HDR_ERROR_T in case of parsing error
* - if emode==1, then parsing does not expect : after header name
+ * - if logmode==1, then print error log messages on parsing failure
* - returns pointer after : if emode==0 or after header name if emode==1
+ * in case of parsing error, returns begin and sets hdr->type to HDR_ERROR_T
*/
char *parse_sip_header_name(char* const begin, const char* const end,
- hdr_field_t* const hdr, int emode)
+ hdr_field_t* const hdr, int emode, int logmode)
{
char *p;
int i;

- if (end <= begin) {
+ if (begin == NULL || end == NULL || end <= begin) {
hdr->type = HDR_ERROR_T;
return begin;
}
if(_ksr_hname_chars_idx[(unsigned char)(*begin)] == 0) {
- LM_ERR("invalid start of header name for [%.*s]\n",
- (int)(end-begin), begin);
+ if(likely(logmode)) {
+ LM_ERR("invalid start of header name for [%.*s]\n",
+ (int)(end-begin), begin);
+ }
hdr->type = HDR_ERROR_T;
return begin;
}
@@ -262,8 +266,10 @@ char *parse_sip_header_name(char* const begin, const char* const end,
}
if(*p != ' ' && *p != '\t') {
/* no white space - bad header name format */
- LM_ERR("invalid header name for [%.*s]\n",
- (int)(end-begin), begin);
+ if(likely(logmode)) {
+ LM_ERR("invalid header name for [%.*s]\n",
+ (int)(end-begin), begin);
+ }
hdr->type = HDR_ERROR_T;
return begin;
}
@@ -271,8 +277,10 @@ char *parse_sip_header_name(char* const begin, const char* const end,

if(p == end) {
/* no : found - emode==0 */
- LM_ERR("invalid end of header name for [%.*s]\n",
- (int)(end-begin), begin);
+ if(likely(logmode)) {
+ LM_ERR("invalid end of header name for [%.*s]\n",
+ (int)(end-begin), begin);
+ }
hdr->type = HDR_ERROR_T;
return begin;
}
@@ -298,7 +306,7 @@ char *parse_sip_header_name(char* const begin, const char* const end,

char* parse_hname2(char* const begin, const char* const end, struct hdr_field* const hdr)
{
- return parse_sip_header_name(begin, end, hdr, 0);
+ return parse_sip_header_name(begin, end, hdr, 0, 1);
}

/**
@@ -307,11 +315,11 @@ char* parse_hname2(char* const begin, const char* const end, struct hdr_field* c
*/
char* parse_hname2_short(char* const begin, const char* const end, struct hdr_field* const hdr)
{
- return parse_sip_header_name(begin, end, hdr, 0);
+ return parse_sip_header_name(begin, end, hdr, 0, 1);
}

char* parse_hname2_str (str* const hbuf, hdr_field_t* const hdr)
{
- return parse_sip_header_name(hbuf->s, hbuf->s + hbuf->len, hdr, 1);
+ return parse_sip_header_name(hbuf->s, hbuf->s + hbuf->len, hdr, 1, 1);
}

diff --git a/src/core/parser/parse_hname2.h b/src/core/parser/parse_hname2.h
index 2c864857d6..fc52c1c802 100644
--- a/src/core/parser/parse_hname2.h
+++ b/src/core/parser/parse_hname2.h
@@ -35,6 +35,15 @@
/** Fast 32-bit header field name parser.
* @file
*/
+
+char *parse_sip_header_name(char* const begin, const char* const end,
+ hdr_field_t* const hdr, int emode, int logmode);
+
+/* macro to find header name without printing errors in failure case */
+#define find_hname2_str(hbuf, hdr) \
+ parse_sip_header_name((hbuf)->s, (hbuf)->s + (hbuf)->len, hdr, 1, 0)
+
+
char* parse_hname2(char* const begin, const char* const end, struct hdr_field* const hdr);
char* parse_hname2_short(char* const begin, const char* const end, struct hdr_field* const hdr);
char* parse_hname2_str (str* const hbuf, hdr_field_t* const hdr);
Loading...