Browse Source

* don't set InOutRes in ConvertToFdRelativePath, but return it instead. This
fixes issues in places where this function is used in a way that should not
set IOResult.

Nikolay Nikolov 3 years ago
parent
commit
aafb471bc8
5 changed files with 33 additions and 38 deletions
  1. 2 2
      rtl/wasi/dos.pp
  2. 7 9
      rtl/wasi/sysdir.inc
  3. 10 10
      rtl/wasi/sysfile.inc
  4. 6 9
      rtl/wasi/system.pp
  5. 8 8
      rtl/wasi/sysutils.pp

+ 2 - 2
rtl/wasi/dos.pp

@@ -464,7 +464,7 @@ var
   pr   : RawByteString;
 begin
   FindGetFileInfo:=false;
-  if not ConvertToFdRelativePath(s,fd,pr) then
+  if ConvertToFdRelativePath(s,fd,pr)<>0 then
     exit;
   { todo: __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW??? }
   if __wasi_path_filestat_get(fd,0,PChar(pr),Length(pr),@st)<>__WASI_ERRNO_SUCCESS then
@@ -556,7 +556,7 @@ Begin
          DirName:='./'
         Else
          DirName:=Copy(f.SearchSpec,1,f.NamePos);
-        if ConvertToFdRelativePath(DirName,fd,pr) then
+        if ConvertToFdRelativePath(DirName,fd,pr)=0 then
          begin
            repeat
              res:=__wasi_path_open(fd,

+ 7 - 9
rtl/wasi/sysdir.inc

@@ -24,12 +24,11 @@ var
   pr: RawByteString;
   res: __wasi_errno_t;
 begin
-  if not ConvertToFdRelativePath(s,fd,pr) then
+  InOutRes:=ConvertToFdRelativePath(s,fd,pr);
+  if InOutRes<>0 then
     exit;
   res:=__wasi_path_create_directory(fd,PChar(pr),Length(pr));
-  if res=__WASI_ERRNO_SUCCESS then
-    InOutRes:=0
-  else
+  if res<>__WASI_ERRNO_SUCCESS then
     InOutRes:=Errno2InoutRes(res);
 end;
 
@@ -39,12 +38,11 @@ var
   pr: RawByteString;
   res: __wasi_errno_t;
 begin
-  if not ConvertToFdRelativePath(s,fd,pr) then
+  InOutRes:=ConvertToFdRelativePath(s,fd,pr);
+  if InOutRes<>0 then
     exit;
   res:=__wasi_path_remove_directory(fd,PChar(pr),Length(pr));
-  if res=__WASI_ERRNO_SUCCESS then
-    InOutRes:=0
-  else
+  if res<>__WASI_ERRNO_SUCCESS then
     InOutRes:=Errno2InoutRes(res);
 end;
 
@@ -136,7 +134,7 @@ begin
           new_dir:=new_dir+next_dir_part
         else
           new_dir:=new_dir+DirectorySeparator+next_dir_part;
-        if not ConvertToFdRelativePath(current_dirs[new_drive_nr].drive_str+new_dir,fd,pr) then
+        if ConvertToFdRelativePath(current_dirs[new_drive_nr].drive_str+new_dir,fd,pr)<>0 then
         begin
           {...}
           InOutRes:=3;

+ 10 - 10
rtl/wasi/sysfile.inc

@@ -32,12 +32,11 @@ var
   pr: RawByteString;
   res: __wasi_errno_t;
 begin
-  if not ConvertToFdRelativePath(p,fd,pr) then
+  InOutRes:=ConvertToFdRelativePath(p,fd,pr);
+  if InOutRes<>0 then
     exit;
   res:=__wasi_path_unlink_file(fd,PChar(pr),Length(pr));
-  if res=__WASI_ERRNO_SUCCESS then
-    InOutRes:=0
-  else
+  if res<>__WASI_ERRNO_SUCCESS then
     InOutRes:=Errno2InoutRes(res);
 end;
 
@@ -58,14 +57,14 @@ var
   pr1,pr2: RawByteString;
   res: __wasi_errno_t;
 begin
-  if not ConvertToFdRelativePath(p1,fd1,pr1) then
+  InOutRes:=ConvertToFdRelativePath(p1,fd1,pr1);
+  if InOutRes<>0 then
     exit;
-  if not ConvertToFdRelativePath(p2,fd2,pr2) then
+  InOutRes:=ConvertToFdRelativePath(p2,fd2,pr2);
+  if InOutRes<>0 then
     exit;
   res:=__wasi_path_rename(fd1,PChar(pr1),Length(pr1),fd2,PChar(pr2),Length(pr2));
-  if res=__WASI_ERRNO_SUCCESS then
-    InOutRes:=0
-  else
+  if res<>__WASI_ERRNO_SUCCESS then
     InOutRes:=Errno2InoutRes(res);
 end;
 
@@ -279,7 +278,8 @@ Begin
      end;
      exit;
    end;
-  if not ConvertToFdRelativePath(p,fd,pr) then
+  InOutRes:=ConvertToFdRelativePath(p,fd,pr);
+  if InOutRes<>0 then
     exit;
 { real open call }
   repeat

+ 6 - 9
rtl/wasi/system.pp

@@ -53,7 +53,7 @@ var
   argv: PPChar;
   envp: PPChar;
 
-function ConvertToFdRelativePath(path: RawByteString; out fd: LongInt; out relfd_path: RawByteString): Boolean;
+function ConvertToFdRelativePath(path: RawByteString; out fd: LongInt; out relfd_path: RawByteString): Word;
 
 implementation
 
@@ -108,7 +108,7 @@ begin
   __wasi_proc_exit(ExitCode);
 End;
 
-function Do_ConvertToFdRelativePath(path: RawByteString; out fd: LongInt; out relfd_path: RawByteString): Boolean;
+function Do_ConvertToFdRelativePath(path: RawByteString; out fd: LongInt; out relfd_path: RawByteString): Word;
 var
   drive_nr,I,pdir_drive,longest_match,chridx: longint;
   IsAbsolutePath: Boolean;
@@ -130,8 +130,7 @@ begin
     { if so, convert to absolute }
     if (drive_nr>=drives_count) or (current_dirs[drive_nr].dir_name='') then
     begin
-      InOutRes:=15;
-      Do_ConvertToFdRelativePath:=false;
+      Do_ConvertToFdRelativePath:=15;
       exit;
     end;
     if current_dirs[drive_nr].dir_name[Length(current_dirs[drive_nr].dir_name)] in AllowDirectorySeparators then
@@ -140,7 +139,6 @@ begin
       path:=current_dirs[drive_nr].dir_name+DirectorySeparator+path;
   end;
   { path is now absolute. Try to find it in the preopened dirs array }
-  Do_ConvertToFdRelativePath:=false;
   longest_match:=0;
   for I:=0 to preopened_dirs_count-1 do
   begin
@@ -166,16 +164,15 @@ begin
         Inc(chridx);
       fd:=preopened_dirs[I].fd;
       relfd_path:=Copy(path,chridx,Length(path)-chridx+1);
-      Do_ConvertToFdRelativePath:=true;
     end;
   end;
   if longest_match>0 then
-    InOutRes:=0
+    Do_ConvertToFdRelativePath:=0
   else
-    InOutRes:=3;
+    Do_ConvertToFdRelativePath:=3;
 end;
 
-function ConvertToFdRelativePath(path: RawByteString; out fd: LongInt; out relfd_path: RawByteString): Boolean;
+function ConvertToFdRelativePath(path: RawByteString; out fd: LongInt; out relfd_path: RawByteString): Word;
 begin
   ConvertToFdRelativePath:=Do_ConvertToFdRelativePath(ToSingleByteFileSystemEncodedFileName(path),fd,relfd_path);
   setcodepage(relfd_path,DefaultRTLFileSystemCodePage,true);

+ 8 - 8
rtl/wasi/sysutils.pp

@@ -237,7 +237,7 @@ Begin
                       __WASI_RIGHTS_FD_DATASYNC or
                       __WASI_RIGHTS_FD_SYNC;
   end;
-  if not ConvertToFdRelativePath(FileName,fd,pr) then
+  if ConvertToFdRelativePath(FileName,fd,pr)<>0 then
     begin
       result:=-1;
       exit;
@@ -282,7 +282,7 @@ Var
   pr: RawByteString;
   fd: __wasi_fd_t;
 Begin
-  if not ConvertToFdRelativePath(FileName,fd,pr) then
+  if ConvertToFdRelativePath(FileName,fd,pr)<>0 then
     begin
       result:=-1;
       exit;
@@ -411,7 +411,7 @@ var
   fd: __wasi_fd_t;
   Info: __wasi_filestat_t;
 begin
-  if not ConvertToFdRelativePath(FileName,fd,pr) then
+  if ConvertToFdRelativePath(FileName,fd,pr)<>0 then
     begin
       result:=-1;
       exit;
@@ -439,7 +439,7 @@ var
 begin
   if FileName='' then
     exit(false);
-  if not ConvertToFdRelativePath(FileName,fd,pr) then
+  if ConvertToFdRelativePath(FileName,fd,pr)<>0 then
     exit(false);
   if FollowLink then
     flags:=__WASI_LOOKUPFLAGS_SYMLINK_FOLLOW
@@ -504,7 +504,7 @@ var
   pr: RawByteString;
   fd: __wasi_fd_t;
 begin
-  if not ConvertToFdRelativePath(FileName,fd,pr) then
+  if ConvertToFdRelativePath(FileName,fd,pr)<>0 then
     begin
       result:=-1;
       exit;
@@ -533,7 +533,7 @@ var
   pr: RawByteString;
   res: __wasi_errno_t;
 begin
-  if not ConvertToFdRelativePath(FileName,fd,pr) then
+  if ConvertToFdRelativePath(FileName,fd,pr)<>0 then
     begin
       result:=false;
       exit;
@@ -549,9 +549,9 @@ var
   res: __wasi_errno_t;
 begin
   result:=false;
-  if not ConvertToFdRelativePath(OldName,fd1,pr1) then
+  if ConvertToFdRelativePath(OldName,fd1,pr1)<>0 then
     exit;
-  if not ConvertToFdRelativePath(NewName,fd2,pr2) then
+  if ConvertToFdRelativePath(NewName,fd2,pr2)<>0 then
     exit;
   result:=__wasi_path_rename(fd1,PChar(pr1),Length(pr1),fd2,PChar(pr2),Length(pr2))=__WASI_ERRNO_SUCCESS;
 end;