Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions components/utilities/ymodem/ry_sy.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,15 @@ static enum rym_code _rym_recv_begin(
rt_size_t len)
{
struct custom_ctx *cctx = (struct custom_ctx *)ctx;
char insert_0 = '\0';
char *ret;
rt_err_t err;
ret = strchr(cctx->fpath,insert_0);
if(ret)
{
*ret = '/';
}
else
{
rt_kprintf("No end character\n");
return RYM_ERR_ACK;
}
rt_strncpy(ret + 1, (const char *)buf, len - 1);
cctx->fd = open(cctx->fpath, O_CREAT | O_WRONLY | O_TRUNC, 0);

/*
support recv multiple files in one session
*/
char user_path[DFS_PATH_MAX]={0};
rt_snprintf(user_path, DFS_PATH_MAX, "%s%s", cctx->fpath, buf);
cctx->fd = open(user_path, O_CREAT | O_WRONLY | O_TRUNC, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char insert_0 = '\0';
    char *ret;
    rt_err_t err;
    ret = strchr(cctx->fpath,insert_0);
    if(ret)
    {
        *ret = '/';
    }
    else
    {
        rt_kprintf("No end character\n");
        return RYM_ERR_ACK;
    }
    rt_strncpy(ret + 1, (const char *)buf, len - 1);
    cctx->fd = open(cctx->fpath, O_CREAT | O_WRONLY | O_TRUNC, 0);
  • 这一块判断逻辑为啥不要了?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段逻辑会直接篡改cctx->fpath,这个cctx->fpath是要传输的目录路径,buf才是文件名,如果按照之前的方式,那么当下载多个文件时,第二个文件的cctx->fpath就不对了,完整路径拼接时会出现问题,路径异常;下面的图是修改后的源码ymodem下载的截图
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充一个图:使用gdb调试,未修改的代码,下载两个文件,第二个文件路径异常:
image


if (cctx->fd < 0)
{
err = rt_get_errno();
Expand Down