[virt-tools-list] [vhostmd PATCH 11/18] util: Check return value of strstr
Jim Fehlig
jfehlig at suse.com
Wed Jan 15 22:07:45 UTC 2020
>From coverity scan
vhostmd-1.1/vhostmd/util.c:421: returned_null: "strstr" returns "NULL" (checked 6 out of 7 times).
Signed-off-by: Jim Fehlig <jfehlig at suse.com>
---
vhostmd/util.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/vhostmd/util.c b/vhostmd/util.c
index 599c5c7..317dbc6 100644
--- a/vhostmd/util.c
+++ b/vhostmd/util.c
@@ -422,10 +422,12 @@ char *vu_str_replace(const char *haystack, const char *origstr, const char *news
cp = tempstr;
for (i=0; i <cnt; i++) {
p = strstr(cp, origstr);
- *p = '\0';
- strcat(dest, cp);
- strcat(dest, newstr);
- cp = p + origlen;
+ if (p) {
+ *p = '\0';
+ strcat(dest, cp);
+ strcat(dest, newstr);
+ cp = p + origlen;
+ }
}
strcat(dest, cp);
--
2.16.4
More information about the virt-tools-list
mailing list