Browse Source

* replaced ['/','\'] with AllowDirectorySeparators in the WASI directory
parsing code

Nikolay Nikolov 3 năm trước cách đây
mục cha
commit
13c344a3a0
3 tập tin đã thay đổi với 12 bổ sung12 xóa
  1. 1 1
      rtl/wasi/dos.pp
  2. 7 7
      rtl/wasi/sysdir.inc
  3. 4 4
      rtl/wasi/system.pp

+ 1 - 1
rtl/wasi/dos.pp

@@ -651,7 +651,7 @@ Begin
   f.SearchAttr := Attr or archive or readonly;
   f.SearchPos  := 0;
   f.NamePos := Length(f.SearchSpec);
-  while (f.NamePos>0) and not (f.SearchSpec[f.NamePos] in ['/','\']) do
+  while (f.NamePos>0) and not (f.SearchSpec[f.NamePos] in AllowDirectorySeparators) do
    dec(f.NamePos);
 {Wildcards?}
   if (Pos('?',Path)=0)  and (Pos('*',Path)=0) then

+ 7 - 7
rtl/wasi/sysdir.inc

@@ -71,7 +71,7 @@ procedure do_ChDir_internal(s: rawbytestring; SymLinkFollowCount: longint);
         result:=s;
         s:='';
       end;
-      while (s<>'') and (s[1] in ['/','\']) do
+      while (s<>'') and (s[1] in AllowDirectorySeparators) do
         delete(s,1,1);
     end;
 
@@ -119,11 +119,11 @@ begin
         {nothing to do}
       else if next_dir_part='..' then
       begin
-        if (new_dir<>'') and not (new_dir[Length(new_dir)] in ['/','\']) then
+        if (new_dir<>'') and not (new_dir[Length(new_dir)] in AllowDirectorySeparators) then
         begin
-          while (new_dir<>'') and not (new_dir[Length(new_dir)] in ['/','\']) do
+          while (new_dir<>'') and not (new_dir[Length(new_dir)] in AllowDirectorySeparators) do
             delete(new_dir,Length(new_dir),1);
-          while (new_dir<>'') and (new_dir[Length(new_dir)] in ['/','\']) do
+          while (new_dir<>'') and (new_dir[Length(new_dir)] in AllowDirectorySeparators) do
             delete(new_dir,Length(new_dir),1);
           if (Pos('/',new_dir)=0) and (Pos('\',new_dir)=0) then
             new_dir:=new_dir+'/';
@@ -132,7 +132,7 @@ begin
       else
       begin
         new_dir_save:=new_dir;
-        if (new_dir<>'') and (new_dir[Length(new_dir)] in ['/','\']) then
+        if (new_dir<>'') and (new_dir[Length(new_dir)] in AllowDirectorySeparators) then
           new_dir:=new_dir+next_dir_part
         else
           new_dir:=new_dir+'/'+next_dir_part;
@@ -161,9 +161,9 @@ begin
             exit;
           end;
           SetLength(symlink,symlink_len);
-          if (symlink<>'') and (symlink[1] in ['/', '\']) then
+          if (symlink<>'') and (symlink[1] in AllowDirectorySeparators) then
             do_ChDir_internal(symlink,SymLinkFollowCount-1)
-          else if (new_dir_save<>'') and (new_dir_save[length(new_dir_save)] in ['/', '\']) then
+          else if (new_dir_save<>'') and (new_dir_save[length(new_dir_save)] in AllowDirectorySeparators) then
             do_ChDir_internal(current_dirs[new_drive_nr].drive_str+new_dir_save+symlink,SymLinkFollowCount-1)
           else
             do_ChDir_internal(current_dirs[new_drive_nr].drive_str+new_dir_save+'/'+symlink,SymLinkFollowCount-1);

+ 4 - 4
rtl/wasi/system.pp

@@ -125,7 +125,7 @@ begin
   else
     drive_nr:=current_drive;
   { path is relative to a current directory? }
-  if (path='') or not (path[1] in ['/','\']) then
+  if (path='') or not (path[1] in AllowDirectorySeparators) then
   begin
     { if so, convert to absolute }
     if (drive_nr>=drives_count) or (current_dirs[drive_nr].dir_name='') then
@@ -134,7 +134,7 @@ begin
       ConvertToFdRelativePath:=false;
       exit;
     end;
-    if current_dirs[drive_nr].dir_name[Length(current_dirs[drive_nr].dir_name)] in ['/','\'] then
+    if current_dirs[drive_nr].dir_name[Length(current_dirs[drive_nr].dir_name)] in AllowDirectorySeparators then
       path:=current_dirs[drive_nr].dir_name+path
     else
       path:=current_dirs[drive_nr].dir_name+'/'+path;
@@ -157,12 +157,12 @@ begin
       continue;
     chridx:=Length(pdir)+1;
     if ((pdir<>'/') and (pdir<>'\')) and
-       ((chridx>Length(path)) or not (path[chridx] in ['/','\'])) then
+       ((chridx>Length(path)) or not (path[chridx] in AllowDirectorySeparators)) then
       continue;
     if Length(pdir)>longest_match then
     begin
       longest_match:=Length(pdir);
-      while (chridx<=Length(path)) and (path[chridx] in ['/','\']) do
+      while (chridx<=Length(path)) and (path[chridx] in AllowDirectorySeparators) do
         Inc(chridx);
       fd:=preopened_dirs[I].fd;
       relfd_path:=Copy(path,chridx,Length(path)-chridx+1);