Module: kamailio
Branch: master
Commit: cbc5034b26189371c2ffb80424414aa8b1b8dea5
URL:
https://github.com/kamailio/kamailio/commit/cbc5034b26189371c2ffb80424414aa…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-09-02T13:07:45+02:00
parser: safer function to parse header name stored in short buffer
---
Modified: parser/parse_hname2.c
Modified: parser/parse_hname2.h
---
Diff:
https://github.com/kamailio/kamailio/commit/cbc5034b26189371c2ffb80424414aa…
Patch:
https://github.com/kamailio/kamailio/commit/cbc5034b26189371c2ffb80424414aa…
---
diff --git a/parser/parse_hname2.c b/parser/parse_hname2.c
index c90d3e5..42fb865 100644
--- a/parser/parse_hname2.c
+++ b/parser/parse_hname2.c
@@ -242,3 +242,31 @@ char* parse_hname2(char* const begin, const char* const end, struct
hdr_field* c
}
}
+/**
+ * parse_hname2_short() - safer version to parse header name stored in short buffers
+ * - parse_hanem2() reads 4 bytes at once, expecting to walk through a buffer
+ * that contains more than the header name (e.g., sip msg buf, full header buf
+ * with name and body)
+ */
+char* parse_hname2_short(char* const begin, const char* const end, struct hdr_field*
const hdr)
+{
+#define HBUF_MAX_SIZE 256
+ char hbuf[HBUF_MAX_SIZE];
+ char *p;
+
+ if(end-begin>=HBUF_MAX_SIZE-4) {
+ p = q_memchr(p, ':', end - begin);
+ if(p && p-4> begin) {
+ /* header name termination char found and enough space in buffer after it */
+ return parse_hname2(begin, end, hdr);
+ }
+ /* not enough space */
+ return NULL;
+ }
+ /* pad with whitespace - tipycal char after the ':' of the header name */
+ memset(hbuf, ' ', HBUF_MAX_SIZE);
+ memcpy(hbuf, begin, end-begin);
+ p = parse_hname2(hbuf, hbuf + 4 + (end-begin), hdr);
+ if(!p) return NULL;
+ return begin + (p-hbuf);
+}
diff --git a/parser/parse_hname2.h b/parser/parse_hname2.h
index 6f5b76b..d44abb7 100644
--- a/parser/parse_hname2.h
+++ b/parser/parse_hname2.h
@@ -36,5 +36,6 @@
* @file
*/
char* parse_hname2(char* const begin, const char* const end, struct hdr_field* const
hdr);
+char* parse_hname2_safe(char* const begin, const char* const end, struct hdr_field* const
hdr);
#endif /* PARSE_HNAME2_H */