Skip to content

Commit b298087

Browse files
authored
fix MSG_STRING_E length issue (#282)
* fix MSG_STRING_E length issue only need copy _n+1 bytes including the tail '\0', the memcpy should be performed when p+_n+1 equals e * add unit test for MSG_STRING_E
1 parent 4cb7477 commit b298087

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

libsofia-sip-ua/msg/sofia-sip/msg_parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ SOFIAPUBFUN issize_t msg_parse_next_field(su_home_t *home, msg_header_t *prev,
224224

225225
/** Encode a string. @HI */
226226
#define MSG_STRING_E(p, e, s) do { \
227-
size_t _n = strlen(s); if (p + _n+1 < e) memcpy(p, s, _n+1); p+= _n; } while(0)
227+
size_t _n = strlen(s); if (p + _n+1 <= e) memcpy(p, s, _n+1); p+= _n; } while(0)
228228

229229
/** Duplicate string. @HI */
230230
#define MSG_STRING_DUP(p, d, s) \

libsofia-sip-ua/msg/test_msg.c

+10
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,16 @@ int test_copy(void)
11741174
msg_destroy(msg1);
11751175
msg_destroy(msg);
11761176

1177+
{
1178+
char dst[8];
1179+
const char *src = "1234567";
1180+
1181+
char *start = &dst;
1182+
char *end = start+sizeof(dst);
1183+
MSG_STRING_E(start, end, src);
1184+
TEST_S(dst, src);
1185+
}
1186+
11771187
END();
11781188
}
11791189

0 commit comments

Comments
 (0)