Skip to contentSkip to conversation

erofs-utils: fix potential buffer overrun in __erofs_io_write()

PATCH New Gao Xiang 1 participant 2 messages Feb 17, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs-utils: fix potential buffer overrun in __erofs_io_write()

.. due to short write, but it's almost impossible for most fses.

Coverity-id: 541575

---
 lib/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/io.c +1 -1
index b6eb22a..5c3d263 100644
@@ -31,7 +31,7 @@ ssize_t __erofs_io_write(int fd, const void *buf, size_t len)
 	ssize_t ret, written = 0;
 
 	do {
-		ret = write(fd, buf, len);
+		ret = write(fd, buf, len - written);
 		if (ret <= 0) {
 			if (!ret)
 				break;
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/2 erofs-utils: lib: fix an API usage error

CID 541574: API usage errors (PRINTF_ARGS)
Argument "rc" to format specifier "%d" was expected to have type "int" but has type "long".

Coverity-id: 541574

---
 lib/fragments.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fragments.c +1 -1
index e22b773..2f5fbf9 100644
@@ -271,7 +271,7 @@ out:
 	if (rc)
 		erofs_err("Failed to record %llu-byte fragment data @ %llu for nid %llu: %d",
 			  inode->fragment_size | 0ULL,
-			  inode->fragmentoff | 0ULL, inode->nid | 0ULL, rc);
+			  inode->fragmentoff | 0ULL, inode->nid | 0ULL, (int)rc);
 	if (memblock)
 		munmap(memblock, inode->i_size);
 	return rc;
Signature · 1 line
2.43.5