dect
/
asterisk
Archived
13
0
Fork 0

Use a better method of ensuring null-termination of the buffer

while reading the SDP when using TCP.



git-svn-id: http://svn.digium.com/svn/asterisk/trunk@218566 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
mmichelson 2009-09-15 15:40:14 +00:00
parent ff9c8e969f
commit 37b9a0031a
1 changed files with 3 additions and 2 deletions

View File

@ -2962,12 +2962,13 @@ static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_sessi
/* In order to know how much to read, we need the content-length header */
if (sscanf(get_header(&reqcpy, "Content-Length"), "%30d", &cl)) {
while (cl > 0) {
size_t bytes_read;
ast_mutex_lock(&tcptls_session->lock);
if (!fread(buf, MIN(sizeof(buf) - 1, cl), 1, tcptls_session->f)) {
if (!(bytes_read = fread(buf, MIN(sizeof(buf) - 1, cl), 1, tcptls_session->f))) {
ast_mutex_unlock(&tcptls_session->lock);
goto cleanup;
}
buf[sizeof(buf)-1] = '\0';
buf[bytes_read] = '\0';
ast_mutex_unlock(&tcptls_session->lock);
if (me->stop)
goto cleanup;