rtspd: fix to check `realloc()` result
No binary (build failed)
—
(log yok)
| @@ -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.", | |