transport: Fix possible NULL ptr deref in pldm_socket_sndbuf_init()
From cppcheck:
```
src/transport/socket.c:24:10: warning: Either the condition 'fp==NULL'
is redundant or there is possible null pointer dereference: fp.
[nullPointerRedundantCheck]
fclose(fp);
^
src/transport/socket.c:23:9: note: Assuming that condition 'fp==NULL' is
not redundant
if (fp == NULL || fgets(line, sizeof(line), fp) == NULL) {
^
src/transport/socket.c:24:10: note: Null pointer dereference
fclose(fp);
^
```
Fixes: 04273e9f6895 ("Resize socket send buffer if needed")
Signed-off-by: Rashmica Gupta <rashmica@linux.ibm.com>
Change-Id: Iac053a3d3c784e3592eea027f25f005dba024850
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e786b5a..4f986af 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -123,6 +123,7 @@
3. transport: mctp-demux: Don't test socket for non-zero value
4. requester: Return PLDM_REQUESTER_OPEN_FAIL from pldm_open() on error
5. pdr: pldm_pdr_fru_record_set_find_by_rsi(): Document reality of return
+6. transport: Fix possible NULL ptr deref in pldm_socket_sndbuf_init()
## [0.3.0] - 2023-06-23
diff --git a/src/transport/socket.c b/src/transport/socket.c
index 6c299a8..8c5dd01 100644
--- a/src/transport/socket.c
+++ b/src/transport/socket.c
@@ -20,7 +20,11 @@
ctx->socket = socket;
fp = fopen("/proc/sys/net/core/wmem_max", "r");
- if (fp == NULL || fgets(line, sizeof(line), fp) == NULL) {
+ if (fp == NULL) {
+ return -1;
+ }
+
+ if (fgets(line, sizeof(line), fp) == NULL) {
fclose(fp);
return -1;
}