Permalink
Browse files

fixed the second bug in #4, with ENAMETOOLONG

  • Loading branch information...
Fleurer committed Apr 1, 2012
1 parent bd8bef4 commit 056e918ed126a214f4530d986412932f48c3fd29
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/kern/sys2.c
View
@@ -27,11 +27,16 @@ int sys_access(struct trap *tf){
struct inode *ip;
int r;
- if (vm_verify(path, strlen(path)+1) < 0) {
+ if (vm_verify(path, MAX_PATHSIZ) < 0) {
syserr(EFAULT);
return -1;
}
+ if (strnlen(path, MAX_PATHSIZ) == MAX_PATHSIZ) {
+ syserr(ENAMETOOLONG);
+ return -1;
+ }
+
ip = namei(path, 0);
if (ip==NULL) {
syserr(ENOENT);
@@ -46,11 +51,16 @@ int sys_open(struct trap *tf){
int mode = tf->edx;
int r;
- if (vm_verify(path, strlen(path)+1) < 0) {
+ if (vm_verify(path, MAX_PATHSIZ) < 0) {
syserr(EFAULT);
return -1;
}
+ if (strnlen(path, MAX_PATHSIZ) == MAX_PATHSIZ) {
+ syserr(ENAMETOOLONG);
+ return -1;
+ }
+
return do_open(path, flag, mode);
}

0 comments on commit 056e918

Please sign in to comment.