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

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Thu Mar 5 09:30:19 CET 2015


At Thu,  5 Mar 2015 14:36:44 +0800,
Xu Yifeng wrote:
> 
> 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(-)

Applied, thanks.
Hitoshi

> 
> 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
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> https://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list