public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
@ 2018-10-04 15:03 Jim.Dailey
  2018-10-08  7:00 ` Ni, Ruiyu
  0 siblings, 1 reply; 7+ messages in thread
From: Jim.Dailey @ 2018-10-04 15:03 UTC (permalink / raw)
  To: edk2-devel; +Cc: michael.d.kinney, liming.gao

MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."

The loop that removes "xxxx\..\" errs when multiple "\.." sequences are
in the path.  Before this change the code would modify a path like
"FS0:\efi\tools\..\.." to "FS0:\efi\\.." and then to "FS0:\efi\", but
the correct path is "FS0:\".

You can test the effect of this change in the shell by setting the
current directory to something like FS0:\efi\boot and then executing
the command "ls ..\..".  Before the change you will see the files in
the FS0:\efi directory; after the change, you will see the files in
the root directory of FS0:.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jim Dailey <jim_dailey@dell.com>
---
 MdePkg/Library/BaseLib/FilePaths.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c
index d6f3758ecb..5d3de01894 100644
--- a/MdePkg/Library/BaseLib/FilePaths.c
+++ b/MdePkg/Library/BaseLib/FilePaths.c
@@ -2,6 +2,7 @@
   Defines file-path manipulation functions.
 
   Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2018, Dell Technologies. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -103,7 +104,9 @@ PathCleanUpDirectories(
         ) {
     *(TempString + 1) = CHAR_NULL;
     PathRemoveLastItem(Path);
-    CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));
+    if (*(TempString + 3)) {
+      CopyMem (Path + StrLen (Path), TempString + 4, StrSize (TempString + 4));
+    }
   }
 
   //
-- 
2.17.0.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
  2018-10-04 15:03 [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.." Jim.Dailey
@ 2018-10-08  7:00 ` Ni, Ruiyu
  2018-10-08 13:23   ` Jim.Dailey
  2018-10-08 15:26   ` Jim.Dailey
  0 siblings, 2 replies; 7+ messages in thread
From: Ni, Ruiyu @ 2018-10-08  7:00 UTC (permalink / raw)
  To: Jim.Dailey, edk2-devel; +Cc: michael.d.kinney, liming.gao

On 10/4/2018 11:03 PM, Jim.Dailey@dell.com wrote:
> MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
> 
> The loop that removes "xxxx\..\" errs when multiple "\.." sequences are
> in the path.  Before this change the code would modify a path like
> "FS0:\efi\tools\..\.." to "FS0:\efi\\.." and then to "FS0:\efi\", but
> the correct path is "FS0:\".
> 
> You can test the effect of this change in the shell by setting the
> current directory to something like FS0:\efi\boot and then executing
> the command "ls ..\..".  Before the change you will see the files in
> the FS0:\efi directory; after the change, you will see the files in
> the root directory of FS0:.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jim Dailey <jim_dailey@dell.com>
> ---
>   MdePkg/Library/BaseLib/FilePaths.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c
> index d6f3758ecb..5d3de01894 100644
> --- a/MdePkg/Library/BaseLib/FilePaths.c
> +++ b/MdePkg/Library/BaseLib/FilePaths.c
> @@ -2,6 +2,7 @@
>     Defines file-path manipulation functions.
>   
>     Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2018, Dell Technologies. All rights reserved.<BR>
>     This program and the accompanying materials
>     are licensed and made available under the terms and conditions of the BSD License
>     which accompanies this distribution.  The full text of the license may be found at
> @@ -103,7 +104,9 @@ PathCleanUpDirectories(
>           ) {
>       *(TempString + 1) = CHAR_NULL;
>       PathRemoveLastItem(Path);
> -    CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));
> +    if (*(TempString + 3)) {
> +      CopyMem (Path + StrLen (Path), TempString + 4, StrSize (TempString + 4));
> +    }
>     }
>   
>     //
> 
Jim,
Are you fixing a corner case bug introduced by following commit:

 > SHA-1: bb99e3282c9e69fbd6365d117c58d15589e34c5d
* MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\"

 > The old code incorrectly cleans path like "fs0:\abc\.\.." to
 > "fs0:\abc", instead of "fs0:\"

 > The patch fixes this bug.


If yes, can you mention the above commit in your commit message?


-- 
Thanks,
Ray


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
  2018-10-08  7:00 ` Ni, Ruiyu
@ 2018-10-08 13:23   ` Jim.Dailey
  2018-10-09  2:55     ` Ni, Ruiyu
  2018-10-08 15:26   ` Jim.Dailey
  1 sibling, 1 reply; 7+ messages in thread
From: Jim.Dailey @ 2018-10-08 13:23 UTC (permalink / raw)
  To: ruiyu.ni; +Cc: michael.d.kinney, liming.gao, edk2-devel

>-----Original Message-----
>From: Ni, Ruiyu [mailto:ruiyu.ni@Intel.com] 
>Sent: Monday, October 8, 2018 2:00 AM
>To: Dailey, Jim; edk2-devel@lists.01.org
>Cc: michael.d.kinney@intel.com; liming.gao@intel.com
>Subject: Re: [edk2] [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
>
>
>On 10/4/2018 11:03 PM, Jim.Dailey@dell.com wrote:
>> MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
>> 
>> The loop that removes "xxxx\..\" errs when multiple "\.." sequences are
>> in the path.  Before this change the code would modify a path like
>> "FS0:\efi\tools\..\.." to "FS0:\efi\\.." and then to "FS0:\efi\", but
>> the correct path is "FS0:\".
>> 
>> You can test the effect of this change in the shell by setting the
>> current directory to something like FS0:\efi\boot and then executing
>> the command "ls ..\..".  Before the change you will see the files in
>> the FS0:\efi directory; after the change, you will see the files in
>> the root directory of FS0:.
>> 
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Jim Dailey <jim_dailey@dell.com>
>> ---
>>   MdePkg/Library/BaseLib/FilePaths.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>> 
>> diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c
>> index d6f3758ecb..5d3de01894 100644
>> --- a/MdePkg/Library/BaseLib/FilePaths.c
>> +++ b/MdePkg/Library/BaseLib/FilePaths.c
>> @@ -2,6 +2,7 @@
>>     Defines file-path manipulation functions.
>>   
>>     Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
>> +  Copyright (c) 2018, Dell Technologies. All rights reserved.<BR>
>>     This program and the accompanying materials
>>     are licensed and made available under the terms and conditions of the BSD License
>>     which accompanies this distribution.  The full text of the license may be found at
>> @@ -103,7 +104,9 @@ PathCleanUpDirectories(
>>           ) {
>>       *(TempString + 1) = CHAR_NULL;
>>       PathRemoveLastItem(Path);
>> -    CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));
>> +    if (*(TempString + 3)) {
>> +      CopyMem (Path + StrLen (Path), TempString + 4, StrSize (TempString + 4));
>> +    }
>>     }
>>   
>>     //
>> 
>Jim,
>Are you fixing a corner case bug introduced by following commit:
>
> > SHA-1: bb99e3282c9e69fbd6365d117c58d15589e34c5d
>* MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\"
>
> > The old code incorrectly cleans path like "fs0:\abc\.\.." to
> > "fs0:\abc", instead of "fs0:\"
>
> > The patch fixes this bug.

Honestly, because of the scope of bb99e328, I cannot say for sure, but
my inclination is to answer "No."

The current fix is strictly related to handling paths that include two
or more references to the previous directory, whether or not one of them
abuts a reference to the current directory (as in the bb99e328 fix).

Regards,
Jim

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
  2018-10-08  7:00 ` Ni, Ruiyu
  2018-10-08 13:23   ` Jim.Dailey
@ 2018-10-08 15:26   ` Jim.Dailey
  2018-10-08 15:46     ` Laszlo Ersek
  1 sibling, 1 reply; 7+ messages in thread
From: Jim.Dailey @ 2018-10-08 15:26 UTC (permalink / raw)
  To: ruiyu.ni; +Cc: edk2-devel, michael.d.kinney, liming.gao

Resending, as I never saw this email on the mailing list.

>-----Original Message-----
>From: Ni, Ruiyu [mailto:ruiyu.ni@Intel.com] 
>Sent: Monday, October 8, 2018 2:00 AM
>To: Dailey, Jim; edk2-devel@lists.01.org
>Cc: michael.d.kinney@intel.com; liming.gao@intel.com
>Subject: Re: [edk2] [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
>
>
>On 10/4/2018 11:03 PM, Jim.Dailey@dell.com wrote:
>> MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
>> 
>> The loop that removes "xxxx\..\" errs when multiple "\.." sequences are
>> in the path.  Before this change the code would modify a path like
>> "FS0:\efi\tools\..\.." to "FS0:\efi\\.." and then to "FS0:\efi\", but
>> the correct path is "FS0:\".
>> 
>> You can test the effect of this change in the shell by setting the
>> current directory to something like FS0:\efi\boot and then executing
>> the command "ls ..\..".  Before the change you will see the files in
>> the FS0:\efi directory; after the change, you will see the files in
>> the root directory of FS0:.
>> 
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Jim Dailey <jim_dailey@dell.com>
>> ---
>>   MdePkg/Library/BaseLib/FilePaths.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>> 
>> diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c
>> index d6f3758ecb..5d3de01894 100644
>> --- a/MdePkg/Library/BaseLib/FilePaths.c
>> +++ b/MdePkg/Library/BaseLib/FilePaths.c
>> @@ -2,6 +2,7 @@
>>     Defines file-path manipulation functions.
>>   
>>     Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
>> +  Copyright (c) 2018, Dell Technologies. All rights reserved.<BR>
>>     This program and the accompanying materials
>>     are licensed and made available under the terms and conditions of the BSD License
>>     which accompanies this distribution.  The full text of the license may be found at
>> @@ -103,7 +104,9 @@ PathCleanUpDirectories(
>>           ) {
>>       *(TempString + 1) = CHAR_NULL;
>>       PathRemoveLastItem(Path);
>> -    CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));
>> +    if (*(TempString + 3)) {
>> +      CopyMem (Path + StrLen (Path), TempString + 4, StrSize (TempString + 4));
>> +    }
>>     }
>>   
>>     //
>> 
>Jim,
>Are you fixing a corner case bug introduced by following commit:
>
> > SHA-1: bb99e3282c9e69fbd6365d117c58d15589e34c5d
>* MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\"
>
> > The old code incorrectly cleans path like "fs0:\abc\.\.." to
> > "fs0:\abc", instead of "fs0:\"
>
> > The patch fixes this bug.

Honestly, because of the scope of bb99e328, I cannot say for sure, but
my inclination is to answer "No."

The current fix is strictly related to handling paths that include two
or more references to the previous directory, whether or not one of them
abuts a reference to the current directory (as in the bb99e328 fix).

Regards,
Jim

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
  2018-10-08 15:26   ` Jim.Dailey
@ 2018-10-08 15:46     ` Laszlo Ersek
  0 siblings, 0 replies; 7+ messages in thread
From: Laszlo Ersek @ 2018-10-08 15:46 UTC (permalink / raw)
  To: Jim.Dailey, ruiyu.ni; +Cc: michael.d.kinney, edk2-devel, liming.gao

(meta)

On 10/08/18 17:26, Jim.Dailey@dell.com wrote:
> Resending, as I never saw this email on the mailing list.

I did -- here's a link to the original in one of the archives too:

http://mid.mail-archive.com/c8ccaad1befc4db4bcd3f835930c2508@ausx13mps335.AMER.DELL.COM

(You were right to re-send, just confirming.)

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
  2018-10-08 13:23   ` Jim.Dailey
@ 2018-10-09  2:55     ` Ni, Ruiyu
  2018-10-09 11:40       ` Jim.Dailey
  0 siblings, 1 reply; 7+ messages in thread
From: Ni, Ruiyu @ 2018-10-09  2:55 UTC (permalink / raw)
  To: Jim.Dailey; +Cc: michael.d.kinney, liming.gao, edk2-devel

On 10/8/2018 9:23 PM, Jim.Dailey@dell.com wrote:
>> -----Original Message-----
>>>
>>> diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c
>>> index d6f3758ecb..5d3de01894 100644
>>> --- a/MdePkg/Library/BaseLib/FilePaths.c
>>> +++ b/MdePkg/Library/BaseLib/FilePaths.c
>>> @@ -2,6 +2,7 @@
>>>      Defines file-path manipulation functions.
>>>    
>>>      Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
>>> +  Copyright (c) 2018, Dell Technologies. All rights reserved.<BR>
>>>      This program and the accompanying materials
>>>      are licensed and made available under the terms and conditions of the BSD License
>>>      which accompanies this distribution.  The full text of the license may be found at
>>> @@ -103,7 +104,9 @@ PathCleanUpDirectories(
>>>            ) {
>>>        *(TempString + 1) = CHAR_NULL;
>>>        PathRemoveLastItem(Path);
>>> -    CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));
>>> +    if (*(TempString + 3)) {
>>> +      CopyMem (Path + StrLen (Path), TempString + 4, StrSize (TempString + 4));
>>> +    }
I just setup a debugging environment to trace the code. Finally I 
understand the issue.
I agree to change "TempString + 3" to "TempString + 4". This can 
eliminate double slash so in next same loop, the pattern "\\..\\" or 
"\\..\0" can be detected and "last item" can be correctly removed by 
PathRemoveLastItem().

Can you change
  "if (*(TempString + 3))"
  to
  "if (*(TempString + 3) != CHAR_NULL)"?

With the above change, Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
If you agree, I can modify your patch and push it for you.

>>>      }
>>>    
>>>      //
>>>
>> Jim,
>> Are you fixing a corner case bug introduced by following commit:
>>
>>> SHA-1: bb99e3282c9e69fbd6365d117c58d15589e34c5d
>> * MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\"
>>
>>> The old code incorrectly cleans path like "fs0:\abc\.\.." to
>>> "fs0:\abc", instead of "fs0:\"
>>
>>> The patch fixes this bug.
> 
> Honestly, because of the scope of bb99e328, I cannot say for sure, but
> my inclination is to answer "No."
> 
> The current fix is strictly related to handling paths that include two
> or more references to the previous directory, whether or not one of them
> abuts a reference to the current directory (as in the bb99e328 fix).
> 
> Regards,
> Jim
> 


-- 
Thanks,
Ray


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
  2018-10-09  2:55     ` Ni, Ruiyu
@ 2018-10-09 11:40       ` Jim.Dailey
  0 siblings, 0 replies; 7+ messages in thread
From: Jim.Dailey @ 2018-10-09 11:40 UTC (permalink / raw)
  To: ruiyu.ni; +Cc: michael.d.kinney, liming.gao, edk2-devel

>-----Original Message-----
>From: Ni, Ruiyu [mailto:ruiyu.ni@Intel.com] 
>Sent: Monday, October 8, 2018 9:55 PM
>To: Dailey, Jim
>Cc: michael.d.kinney@intel.com; liming.gao@intel.com; edk2-devel@lists.01.org
>Subject: Re: [edk2] [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."
>
>
>On 10/8/2018 9:23 PM, Jim.Dailey@dell.com wrote:
>>> -----Original Message-----
>>>>
>>>> diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c
>>>> index d6f3758ecb..5d3de01894 100644
>>>> --- a/MdePkg/Library/BaseLib/FilePaths.c
>>>> +++ b/MdePkg/Library/BaseLib/FilePaths.c
>>>> @@ -2,6 +2,7 @@
>>>>      Defines file-path manipulation functions.
>>>>    
>>>>      Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
>>>> +  Copyright (c) 2018, Dell Technologies. All rights reserved.<BR>
>>>>      This program and the accompanying materials
>>>>      are licensed and made available under the terms and conditions of the BSD License
>>>>      which accompanies this distribution.  The full text of the license may be found at
>>>> @@ -103,7 +104,9 @@ PathCleanUpDirectories(
>>>>            ) {
>>>>        *(TempString + 1) = CHAR_NULL;
>>>>        PathRemoveLastItem(Path);
>>>> -    CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));
>>>> +    if (*(TempString + 3)) {
>>>> +      CopyMem (Path + StrLen (Path), TempString + 4, StrSize (TempString + 4));
>>>> +    }
>I just setup a debugging environment to trace the code. Finally I 
>understand the issue.
>I agree to change "TempString + 3" to "TempString + 4". This can 
>eliminate double slash so in next same loop, the pattern "\\..\\" or 
>"\\..\0" can be detected and "last item" can be correctly removed by 
>PathRemoveLastItem().
>
>Can you change
>  "if (*(TempString + 3))"
>  to
>  "if (*(TempString + 3) != CHAR_NULL)"?
>
>With the above change, Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
>If you agree, I can modify your patch and push it for you.
>
>-- 
>Thanks,
>Ray

Sure, I have no problem with `*(TempString + 3) != CHAR_NULL`. Feel
free to make that change and push it.

Thanks,
Jim

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-10-09 11:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-04 15:03 [PATCH] MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.." Jim.Dailey
2018-10-08  7:00 ` Ni, Ruiyu
2018-10-08 13:23   ` Jim.Dailey
2018-10-09  2:55     ` Ni, Ruiyu
2018-10-09 11:40       ` Jim.Dailey
2018-10-08 15:26   ` Jim.Dailey
2018-10-08 15:46     ` Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox