Prevent a possible negative value of an argument 27/307427/2 accepted/tizen/unified/20240311.170354 accepted/tizen/unified/x/20240313.092056
authorSung-hun Kim <sfoon.kim@samsung.com>
Fri, 8 Mar 2024 05:57:10 +0000 (14:57 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Fri, 8 Mar 2024 07:32:20 +0000 (16:32 +0900)
If a given argument len has a negative value, it can incur infinite loop.

This patch fixes a coverity issue (cid: 1757405).

Change-Id: Iaafad7cd1afe899de5ec2441ef58398927a472e2
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
src/shared/util.c

index da130e6..eac3506 100644 (file)
@@ -40,6 +40,8 @@ int write_fd(int fd, const void *buf, int len)
        int count;
        int total;
        total = 0;
+       if (len < 0)
+               return 0;
        while (len) {
                count = write(fd, buf, len);
                if (count < 0) {