Skip to contentSkip to conversation

fs: dlm: keep room for the final NUL in comm_addr_list_show()

PATCH New Pengpeng Hou 1 participant 1 message Mar 25 Distributed lock manager (DLM)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: dlm: keep room for the final NUL in comm_addr_list_show()

comm_addr_list_show() subtracts the formatted address length from the remaining configfs buffer allowance before appending the string with strcat(). When the remaining allowance reaches exactly 0, strcat() still writes the terminating NUL one byte past the 4096-byte configfs buffer.

Only append the next address string when there is still positive space left after subtracting its visible length, so the trailing NUL stays inside the output buffer.

Fixes 55b3286d3dfd ("dlm: show addresses in configfs")
---
 fs/dlm/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dlm/config.c +1 -1
index 53cd33293042..94e4e8d3de3d 100644
@@ -752,7 +752,7 @@ static ssize_t comm_addr_list_show(struct config_item *item, char *buf)
 			break;
 		}
 		allowance -= s;
-		if (allowance >= 0)
+		if (allowance > 0)
 			strcat(buf, buf0);
 		else {
 			allowance += s;
Signature · 1 line
2.50.1 (Apple Git-155)