[sr-dev] git:master:2531dd06: pv: Use memcpy to copy len bytes instead of strcpy

Holger Hans Peter Freyther holger at moiji-mobile.com
Fri Oct 28 12:04:50 CEST 2016


Module: kamailio
Branch: master
Commit: 2531dd069bc76f945c5c19253e35fe8b1ef9ed15
URL: https://github.com/kamailio/kamailio/commit/2531dd069bc76f945c5c19253e35fe8b1ef9ed15

Author: Holger Hans Peter Freyther <holger at moiji-mobile.com>
Committer: Holger Hans Peter Freyther <holger at moiji-mobile.com>
Date: 2016-10-25T23:01:14+02:00

pv: Use memcpy to copy len bytes instead of strcpy

The sipcapture plugin stores bytes with VAR_VAL_STR and when
copying the data it would end up being truncated. Use memcpy
instead of strncpy and assume that the original string already
has the NUL termination (or not as with the hep plugin).

Config example:

	$var(payload) = hep(0x00f)

---

Modified: modules/pv/pv_svar.c

---

Diff:  https://github.com/kamailio/kamailio/commit/2531dd069bc76f945c5c19253e35fe8b1ef9ed15.diff
Patch: https://github.com/kamailio/kamailio/commit/2531dd069bc76f945c5c19253e35fe8b1ef9ed15.patch

---

diff --git a/modules/pv/pv_svar.c b/modules/pv/pv_svar.c
index 3b4c710..ae22db1 100644
--- a/modules/pv/pv_svar.c
+++ b/modules/pv/pv_svar.c
@@ -70,7 +70,7 @@ script_var_t* add_var(str *name, int vtype)
 		return 0;
 	}
 	it->name.len = name->len;
-	strncpy(it->name.s, name->s, name->len);
+	memcpy(it->name.s, name->s, name->len);
 	it->name.s[it->name.len] = '\0';
 
 	if(vtype==VAR_TYPE_NULL) {
@@ -133,7 +133,7 @@ script_var_t* set_var_value(script_var_t* var, int_str *value, int flags)
 			}
 			var->v.flags |= VAR_VAL_STR;
 		}
-		strncpy(var->v.value.s.s, value->s.s, value->s.len);
+		memcpy(var->v.value.s.s, value->s.s, value->s.len);
 		var->v.value.s.len = value->s.len;
 		var->v.value.s.s[value->s.len] = '\0';
 	} else {




More information about the sr-dev mailing list