Skip to content

Commit 63c7d0c

Browse files
xqyjljGuozhanxin
authored andcommitted
🐞 fix(components/lwp/lwp_syscall.c): fix sys_readlink
1 parent 157dc09 commit 63c7d0c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

components/lwp/lwp_syscall.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4157,7 +4157,7 @@ sysret_t sys_getrandom(void *buf, size_t buflen, unsigned int flags)
41574157
ssize_t sys_readlink(char* path, char *buf, size_t bufsz)
41584158
{
41594159
size_t len, copy_len;
4160-
int err;
4160+
int err, rtn;
41614161
int fd = -1;
41624162
struct dfs_fd *d;
41634163
char *copy_path;
@@ -4184,12 +4184,25 @@ ssize_t sys_readlink(char* path, char *buf, size_t bufsz)
41844184

41854185
/* musl __procfdname */
41864186
err = sscanf(copy_path, "/proc/self/fd/%d", &fd);
4187-
rt_free(copy_path);
41884187

41894188
if (err != 1)
41904189
{
4191-
LOG_E("readlink: path not is /proc/self/fd/* , call by musl __procfdname()?");
4192-
return -EINVAL;
4190+
rtn = 0;
4191+
if (access(copy_path, 0))
4192+
{
4193+
rtn = -ENOENT;
4194+
LOG_E("readlink: path not is /proc/self/fd/* and path not exits, call by musl __procfdname()?");
4195+
}
4196+
else
4197+
{
4198+
rtn = lwp_put_to_user(buf, copy_path, copy_len);
4199+
}
4200+
rt_free(copy_path);
4201+
return rtn;
4202+
}
4203+
else
4204+
{
4205+
rt_free(copy_path);
41934206
}
41944207

41954208
d = fd_get(fd);

0 commit comments

Comments
 (0)