[sheepdog] [PATCH] sheep: fix side-effect of dirname()
Liu Yuan
namei.unix at gmail.com
Thu Mar 5 06:25:54 CET 2015
On Wed, Mar 04, 2015 at 10:06:31PM +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(-)
>
> 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
Please use git to generate the appliable patch. Git report cupported patch line.
Yuan
More information about the sheepdog
mailing list