From 2f15656bc3532357f6e171161db7762ae292d805 Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 8 Sep 2022 09:49:02 -0400 Subject: [PATCH 1/7] wsevh: optimize string length check --- src/events/janus_wsevh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/janus_wsevh.c b/src/events/janus_wsevh.c index dd35e1714b..0d55eaae6b 100644 --- a/src/events/janus_wsevh.c +++ b/src/events/janus_wsevh.c @@ -376,7 +376,7 @@ int janus_wsevh_init(const char *config_path) { goto error; } path[0] = '/'; - if(strlen(p) > 1) + if(strnlen(p, 1 + 1) > 1) g_strlcpy(path + 1, p, sizeof(path)-2); /* Before connecting, let's check if the server expects a subprotocol */ item = janus_config_get(config, config_general, janus_config_type_item, "subprotocol"); From 10dfb7678b86cecad2160bb0ea33dd0840d71e6e Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 8 Sep 2022 09:49:45 -0400 Subject: [PATCH 2/7] streaming: optimize string length checks --- src/plugins/janus_streaming.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/janus_streaming.c b/src/plugins/janus_streaming.c index faa2ae2d80..8bd366276f 100644 --- a/src/plugins/janus_streaming.c +++ b/src/plugins/janus_streaming.c @@ -7663,7 +7663,7 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp index++; continue; } - if(strlen(line) < 3) { + if(strnlen(line, 3) < 3) { JANUS_LOG(LOG_ERR, "Invalid RTSP line (%zu bytes): %s\n", strlen(line), line); success = FALSE; break; @@ -7843,7 +7843,7 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp index++; continue; } - if(strlen(line) < 3) { + if(strnlen(line, 3) < 3) { JANUS_LOG(LOG_ERR, "Invalid RTSP line (%zu bytes): %s\n", strlen(line), line); success = FALSE; break; From 6f9cb160aca3f0267b3eae979248c742076211bb Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 8 Sep 2022 09:50:55 -0400 Subject: [PATCH 3/7] pp-rec: optimize string length check --- src/postprocessing/janus-pp-rec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/postprocessing/janus-pp-rec.c b/src/postprocessing/janus-pp-rec.c index 1f63af47fe..a340f6242e 100644 --- a/src/postprocessing/janus-pp-rec.c +++ b/src/postprocessing/janus-pp-rec.c @@ -198,7 +198,7 @@ static char *janus_pp_extensions_string(const char **allowed, char *supported, s janus_strlcat(supported, "[", suplen); const char **ext = allowed; while(*ext != NULL) { - if(strlen(supported) > 1) + if(strnlen(supported, 1 + 1) > 1) janus_strlcat(supported, ", ", suplen); janus_strlcat(supported, *ext, suplen); ext++; From dd2a0986473468cdc4de9e5a74717b4d88cb630e Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 8 Sep 2022 09:51:20 -0400 Subject: [PATCH 4/7] sdp-utils: optimize string length checks --- src/sdp-utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdp-utils.c b/src/sdp-utils.c index 90548549aa..9a87437165 100644 --- a/src/sdp-utils.c +++ b/src/sdp-utils.c @@ -327,7 +327,7 @@ janus_sdp *janus_sdp_parse(const char *sdp, char *error, size_t errlen) { index++; continue; } - if(strlen(line) < 3) { + if(strnlen(line, 3) < 3) { if(error) g_snprintf(error, errlen, "Invalid line (%zu bytes): %s", strlen(line), line); success = FALSE; @@ -465,7 +465,7 @@ janus_sdp *janus_sdp_parse(const char *sdp, char *error, size_t errlen) { /* Start with media type, port and protocol */ char type[32]; char proto[64]; - if(strlen(line) > 200) { + if(strnlen(line, 200 + 1) > 200) { janus_sdp_mline_destroy(m); if(error) g_snprintf(error, errlen, "Invalid m= line (too long): %zu", strlen(line)); From b5d38eefe285fc7700c8ad2409f7b8d1417381dd Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 8 Sep 2022 09:51:31 -0400 Subject: [PATCH 5/7] sdp: optimize string length checks --- src/sdp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sdp.c b/src/sdp.c index 3b014a487d..853ca3d34e 100644 --- a/src/sdp.c +++ b/src/sdp.c @@ -100,7 +100,7 @@ janus_sdp *janus_sdp_preparse(void *ice_handle, const char *jsep_sdp, char *erro return NULL; } if((m->type == JANUS_SDP_AUDIO || m->type == JANUS_SDP_VIDEO) && m->port > 0) { - if(strlen(a->value) > 16) { + if(strnlen(a->value, 16 + 1) > 16) { JANUS_LOG(LOG_ERR, "[%"SCNu64"] mid on m-line #%d too large: (%zu > 16)\n", handle->handle_id, m->index, strlen(a->value)); janus_sdp_destroy(parsed_sdp); @@ -298,7 +298,7 @@ int janus_sdp_process_remote(void *ice_handle, janus_sdp *remote_sdp, gboolean r if(a->name && a->value) { if(!strcasecmp(a->name, "mid")) { /* Found mid attribute */ - if(strlen(a->value) > 16) { + if(strnlen(a->value, 16 + 1) > 16) { JANUS_LOG(LOG_ERR, "[%"SCNu64"] mid on m-line #%d too large: (%zu > 16)\n", handle->handle_id, m->index, strlen(a->value)); return -2; @@ -759,7 +759,7 @@ int janus_sdp_process_local(void *ice_handle, janus_sdp *remote_sdp, gboolean up if(a->name && a->value) { if(!strcasecmp(a->name, "mid")) { /* Found mid attribute */ - if(strlen(a->value) > 16) { + if(strnlen(a->value, 16 + 1) > 16) { JANUS_LOG(LOG_ERR, "[%"SCNu64"] mid on m-line #%d too large: (%zu > 16)\n", handle->handle_id, m->index, strlen(a->value)); return -2; From 7c8e1964451b9c84d37eb8bd1421e8bbb428f5aa Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 8 Sep 2022 09:53:53 -0400 Subject: [PATCH 6/7] http: optimize string length checks --- src/transports/janus_http.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/transports/janus_http.c b/src/transports/janus_http.c index a5a76470e5..8bfd12772f 100644 --- a/src/transports/janus_http.c +++ b/src/transports/janus_http.c @@ -685,7 +685,7 @@ int janus_http_init(janus_transport_callbacks *callback, const char *config_path return -1; } ws_path = g_strdup(item->value); - if(strlen(ws_path) > 1 && ws_path[strlen(ws_path)-1] == '/') { + if(strnlen(ws_path, 1 + 1) > 1 && ws_path[strlen(ws_path)-1] == '/') { /* Remove the trailing slash, it makes things harder when we parse requests later */ ws_path[strlen(ws_path)-1] = '\0'; } @@ -700,7 +700,7 @@ int janus_http_init(janus_transport_callbacks *callback, const char *config_path return -1; } admin_ws_path = g_strdup(item->value); - if(strlen(admin_ws_path) > 1 && admin_ws_path[strlen(admin_ws_path)-1] == '/') { + if(strnlen(admin_ws_path, 1 + 1) > 1 && admin_ws_path[strlen(admin_ws_path)-1] == '/') { /* Remove the trailing slash, it makes things harder when we parse requests later */ admin_ws_path[strlen(admin_ws_path)-1] = '\0'; } @@ -1423,7 +1423,7 @@ static MHD_Result janus_http_handler(void *cls, struct MHD_Connection *connectio } /* Get path components */ if(strcasecmp(url, ws_path)) { - if(strlen(ws_path) > 1) { + if(strnlen(ws_path, 1 + 1) > 1) { basepath = g_strsplit(url, ws_path, -1); } else { /* The base path is the web server too itself, we process the url itself */ @@ -1821,7 +1821,7 @@ static MHD_Result janus_http_admin_handler(void *cls, struct MHD_Connection *con } /* Get path components */ if(strcasecmp(url, admin_ws_path)) { - if(strlen(admin_ws_path) > 1) { + if(strnlen(admin_ws_path, 1 + 1) > 1) { basepath = g_strsplit(url, admin_ws_path, -1); } else { /* The base path is the web server too itself, we process the url itself */ From 6556ba7601a811a37d3c3c3f417f21e0fb014e56 Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 8 Sep 2022 09:54:14 -0400 Subject: [PATCH 7/7] transports: unix: optimize string length check --- src/transports/janus_pfunix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transports/janus_pfunix.c b/src/transports/janus_pfunix.c index c953de6a24..73b045e3e6 100644 --- a/src/transports/janus_pfunix.c +++ b/src/transports/janus_pfunix.c @@ -180,7 +180,7 @@ static int janus_pfunix_create_socket(char *pfname, gboolean use_dgram) { if(pfname == NULL) return -1; int fd = -1; - if(strlen(pfname) > UNIX_PATH_MAX) { + if(strnlen(pfname, UNIX_PATH_MAX + 1) > UNIX_PATH_MAX) { JANUS_LOG(LOG_WARN, "The provided path name (%s) is longer than %lu characters, it will be truncated\n", pfname, UNIX_PATH_MAX); pfname[UNIX_PATH_MAX] = '\0'; }