From 7c01bb23bc8454427149f31f4dae0c60c2991c15 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 18 Feb 2026 19:04:12 +0100 Subject: [PATCH] rtspd: fix to check `realloc()` result Also enable `bugprone-suspicious-realloc-usage` clang-tidy option to verify. Fixing: ``` tests/server/rtspd.c:328:37: error: 'req->rtp_buffer' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage,-warnings-as-errors] 328 | req->rtp_buffer = realloc(req->rtp_buffer, | ~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~ ``` Ref: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/suspicious-realloc-usage.html Closes #20621 --- .clang-tidy.yml | 1 + tests/server/rtspd.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.clang-tidy.yml b/.clang-tidy.yml index 751ffcef52..91a83733eb 100644 --- a/.clang-tidy.yml +++ b/.clang-tidy.yml @@ -12,5 +12,6 @@ Checks: >- -clang-analyzer-security.ArrayBound, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -clang-diagnostic-nullability-extension, + bugprone-suspicious-realloc-usage, misc-const-correctness, portability-* diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index f9a5f7a84f..80eb22abf2 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -325,12 +325,17 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) req->rtp_buffersize = rtp_size + 4; } else { - req->rtp_buffer = realloc(req->rtp_buffer, - req->rtp_buffersize + - rtp_size + 4); - memcpy(req->rtp_buffer + req->rtp_buffersize, rtp_scratch, - rtp_size + 4); - req->rtp_buffersize += rtp_size + 4; + char *rtp_buffer = realloc(req->rtp_buffer, + req->rtp_buffersize + + rtp_size + 4); + if(rtp_buffer) { + req->rtp_buffer = rtp_buffer; + memcpy(req->rtp_buffer + req->rtp_buffersize, rtp_scratch, + rtp_size + 4); + req->rtp_buffersize += rtp_size + 4; + } + else + logmsg("failed resizing buffer."); free(rtp_scratch); } logmsg("rtp_buffersize is %zu, rtp_size is %d.",