[sheepdog] [PATCH] fix side-effect of dirname()

Xu Yifeng skypexu at gmail.com
Thu Mar 5 07:36:44 CET 2015


dirname() modifies path buffer parameter, and later we pass the modified
buffer to err_to_sderr() which expects a full path contains filename,
cause the function to work incorrectly. To fix this bug, we reuse tmp_path,
copy path to it, and use it as a parameter for dirname().

Signed-off-by: Xu Yifeng <skypexu at gmail.com>
---
 sheep/plain_store.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 5a424bd..4c19832 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -470,7 +470,8 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 		return SD_RES_SUCCESS;
 	}
 
-	dir = dirname(path);
+	pstrcpy(tmp_path, sizeof(tmp_path), path);
+	dir = dirname(tmp_path);
 	fd = open(dir, O_DIRECTORY | O_RDONLY);
 	if (fd < 0) {
 		sd_err("failed to open directory %s: %m", dir);
-- 
2.1.0




More information about the sheepdog mailing list