[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 2/2] cxl-cdat:Fix the check on the return value of fread()
From: |
Hao Zeng |
Subject: |
[PATCH v2 2/2] cxl-cdat:Fix the check on the return value of fread() |
Date: |
Wed, 12 Apr 2023 15:16:33 +0800 |
The bug in this code (CID 1507822) is that the
check on the return value of fread() is wrong. fread()
returns the number of items read or written, so
checking for == 0 only catches "no data read at all",
not "only read half the data".
Signed-off-by: Zeng Hao <zenghao@kylinos.cn>
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/cxl/cxl-cdat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/cxl/cxl-cdat.c b/hw/cxl/cxl-cdat.c
index ba7ed1aafd..130531a9cd 100644
--- a/hw/cxl/cxl-cdat.c
+++ b/hw/cxl/cxl-cdat.c
@@ -126,7 +126,7 @@ static void ct3_load_cdat(CDATObject *cdat, Error **errp)
fseek(fp, 0, SEEK_SET);
cdat->buf = g_malloc0(file_size);
- if (fread(cdat->buf, file_size, 1, fp) == 0) {
+ if (fread(cdat->buf, file_size, 1, fp) != file_size) {
error_setg(errp, "CDAT: File read failed");
fclose(fp);
return;
--
2.37.2
No virus found
Checked by Hillstone Network AntiVirus