mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
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
This commit is contained in:
parent
7e203c15e6
commit
7c01bb23bc
@ -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-*
|
||||
|
||||
@ -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.",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user