kernel: usercopy functions

This commit is contained in:
Matheus
2024-06-09 19:31:26 -03:00
parent 429f56aced
commit 50b4b45d00
53 changed files with 712 additions and 260 deletions
+17 -6
View File
@@ -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;