Patchwork [U-Boot] cramfs: fix bug for wrong filename comparison

login
register
mail settings
Submitter Holger Brunck
Date July 4, 2013, 8:29 a.m.
Message ID <1372926586-14495-1-git-send-email-holger.brunck@keymile.com>
Download mbox | patch
Permalink /patch/256819/
State Superseded
Delegated to: Albert ARIBAUD
Headers show

Comments

Holger Brunck - July 4, 2013, 8:29 a.m.
If we have the following entry in cramfs:
=> cramfsls
 -rw-r--r--  1922689 uImage

cramfsload would also succeed if we try to do:
=> cramfsload uImage_1
CRAMFS load complete: 1922689 bytes loaded to 0x100000

The old code succeeds if the begin of the filename we search matches
with a filename stored in cramfs. But the searched file may have
additional characters and is therfore not the file we are looking for.
So compare also the length of the filename we search and the
filename we found in cramfs. This leads to:
=> cramfsload uImage_1
can't find corresponding entry
CRAMFS LOAD ERROR<0> for uImage_1!

which is the behaviour we want.

Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
cc: Wolfgang Denk <wd@denx.de>
---
 fs/cramfs/cramfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Albert ARIBAUD - July 5, 2013, 9:23 p.m.
Hi Holger,

On Thu,  4 Jul 2013 10:29:46 +0200, Holger Brunck
<holger.brunck@keymile.com> wrote:

> If we have the following entry in cramfs:
> => cramfsls
>  -rw-r--r--  1922689 uImage
> 
> cramfsload would also succeed if we try to do:
> => cramfsload uImage_1
> CRAMFS load complete: 1922689 bytes loaded to 0x100000
> 
> The old code succeeds if the begin of the filename we search matches
> with a filename stored in cramfs. But the searched file may have
> additional characters and is therfore not the file we are looking for.
> So compare also the length of the filename we search and the
> filename we found in cramfs. This leads to:
> => cramfsload uImage_1
> can't find corresponding entry
> CRAMFS LOAD ERROR<0> for uImage_1!
> 
> which is the behaviour we want.
> Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
> cc: Wolfgang Denk <wd@denx.de>
> ---

Can't the commit message above be summarized as follows?

---8<---
"cramfsload uImage_1" succeeds even though the actual file is named
"uImage".

Fix file name comparison when one name is the prefix of the other.
---8<---

The demonstrative part of the commit message can go here, below the
commit message delimiter '---'.

>  fs/cramfs/cramfs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c
> index 910955d..e578a1e 100644
> --- a/fs/cramfs/cramfs.c
> +++ b/fs/cramfs/cramfs.c
> @@ -126,7 +126,8 @@ static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset,
>  			namelen--;
>  		}
>  
> -		if (!strncmp (filename, name, namelen)) {
> +		if (!strncmp(filename, name, namelen) &&
> +		    (namelen == strlen(filename))) {
>  			char *p = strtok (NULL, "/");
>  
>  			if (raw && (p == NULL || *p == '\0'))


Amicalement,
Holger Brunck - July 8, 2013, 6:53 a.m.
On 07/05/2013 11:23 PM, Albert ARIBAUD wrote:
> On Thu,  4 Jul 2013 10:29:46 +0200, Holger Brunck
> <holger.brunck@keymile.com> wrote:
> 
>> If we have the following entry in cramfs:
>> => cramfsls
>>  -rw-r--r--  1922689 uImage
>>
>> cramfsload would also succeed if we try to do:
>> => cramfsload uImage_1
>> CRAMFS load complete: 1922689 bytes loaded to 0x100000
>>
>> The old code succeeds if the begin of the filename we search matches
>> with a filename stored in cramfs. But the searched file may have
>> additional characters and is therfore not the file we are looking for.
>> So compare also the length of the filename we search and the
>> filename we found in cramfs. This leads to:
>> => cramfsload uImage_1
>> can't find corresponding entry
>> CRAMFS LOAD ERROR<0> for uImage_1!
>>
>> which is the behaviour we want.
>> Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
>> cc: Wolfgang Denk <wd@denx.de>
>> ---
> 
> Can't the commit message above be summarized as follows?
> 
> ---8<---
> "cramfsload uImage_1" succeeds even though the actual file is named
> "uImage".
> 
> Fix file name comparison when one name is the prefix of the other.
> ---8<---
> 
> The demonstrative part of the commit message can go here, below the
> commit message delimiter '---'.
> 

ok. I'll send a v2.

Regards
Holger

Patch

diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c
index 910955d..e578a1e 100644
--- a/fs/cramfs/cramfs.c
+++ b/fs/cramfs/cramfs.c
@@ -126,7 +126,8 @@  static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset,
 			namelen--;
 		}
 
-		if (!strncmp (filename, name, namelen)) {
+		if (!strncmp(filename, name, namelen) &&
+		    (namelen == strlen(filename))) {
 			char *p = strtok (NULL, "/");
 
 			if (raw && (p == NULL || *p == '\0'))