mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 22:48:21 +00:00
kernel: usercopy functions
This commit is contained in:
@@ -2,27 +2,38 @@
|
||||
#include <kernel/alloc.h>
|
||||
|
||||
|
||||
syscallret_t syscall_linkat(context_t *, int olddirfd, const char *uoldpath, int newdirfd, const char *unewpath, int flags, int type) {
|
||||
syscallret_t syscall_linkat(context_t *, int olddirfd, char *uoldpath, int newdirfd, char *unewpath, int flags, int type) {
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
char *oldpath = alloc(strlen(uoldpath) + 1);
|
||||
size_t oldpathlen;
|
||||
size_t newpathlen;
|
||||
|
||||
if (usercopy_strlen(uoldpath, &oldpathlen) || usercopy_strlen(unewpath, &newpathlen)) {
|
||||
ret.errno = EFAULT;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *oldpath = alloc(oldpathlen + 1);
|
||||
if (oldpath == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *newpath = alloc(strlen(unewpath) + 1);
|
||||
char *newpath = alloc(newpathlen + 1);
|
||||
if (newpath == NULL) {
|
||||
free(oldpath);
|
||||
ret.errno = ENOMEM;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO safe strcopy
|
||||
strcpy(oldpath, uoldpath);
|
||||
strcpy(newpath, unewpath);
|
||||
if (usercopy_fromuser(oldpath, uoldpath, oldpathlen) || usercopy_fromuser(newpath, unewpath, newpathlen)) {
|
||||
ret.errno = EFAULT;
|
||||
free(newpath);
|
||||
free(oldpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
vnode_t *olddirnode = NULL;
|
||||
file_t *oldfile = NULL;
|
||||
|
||||
Reference in New Issue
Block a user