Driver: Buffer: Fix PVS-Studio warning.

V1004 The 'data' pointer was used unsafely after it was verified against nullptr. Check lines: 123, 132. fortbuf.c 132
This commit is contained in:
Nodir Temirkhodjaev 2021-06-18 22:07:05 +03:00
parent 5a8f2cb640
commit 57e9528f95

View File

@ -120,17 +120,13 @@ FORT_API NTSTATUS fort_buffer_prepare(
buf->out_top = new_top; buf->out_top = new_top;
} else { } else {
PFORT_BUFFER_DATA data = fort_buffer_data_alloc(buf, len); PFORT_BUFFER_DATA data = fort_buffer_data_alloc(buf, len);
const UINT32 buf_top = data ? data->top : FORT_BUFFER_SIZE; if (data == NULL) {
const UINT32 new_top = buf_top + len; DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, "FORT: Buffer OOM: len=%d\n", len);
return STATUS_INSUFFICIENT_RESOURCES;
if (new_top > FORT_BUFFER_SIZE) {
DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL,
"FORT: Buffer Overflow: data=%p len=%d\n", data, len);
return STATUS_BUFFER_TOO_SMALL; /* drop on buffer overflow */
} }
*out = data->p + buf_top; *out = data->p + data->top;
data->top = new_top; data->top += len;
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;