Skip to contentSkip to conversation

fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

PATCH New Richard Genoud 2 participants 12 messages Dec 18, 2020 – Dec 22, 2020 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

token_count may be != 0 and token_list not yet allocated when the out code is reached

Reported-by Coverity CID 313547
Fixes ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")
---
 fs/squashfs/sqfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/squashfs/sqfs.c +3 -2
index 608a2bb454c..c47046b76e5 100644
@@ -949,8 +949,9 @@ int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp)
 	*dirsp = (struct fs_dir_stream *)dirs;
 
 out:
-	for (j = 0; j < token_count; j++)
-		free(token_list[j]);
+	if (token_list)
+		for (j = 0; j < token_count; j++)
+			free(token_list[j]);
 	free(token_list);
 	free(pos_list);
 	free(path);
#1 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

Quoted 2 lines

token_count may be != 0 and token_list not yet allocated when the out code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Quoted 14 lines
Reported-by Coverity CID 313547
Fixes ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")
---
 fs/squashfs/sqfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/squashfs/sqfs.c +0 -0
index 608a2bb454c..c47046b76e5 100644
@@ -949,8 +949,9 @@ int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp)
 	*dirsp = (struct fs_dir_stream *)dirs;

fs/squashfs/sqfs.c int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp) · line 957

Quoted 10 lines
fs/squashfs/sqfs.c +3 -2
 
 out:
-	for (j = 0; j < token_count; j++)
-		free(token_list[j]);
+	if (token_list)
+		for (j = 0; j < token_count; j++)
+			free(token_list[j]);
 	free(token_list);
 	free(pos_list);
 	free(path);

Thanks,
Miqu?l

#2 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 10 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

Quoted 2 lines

token_count may be != 0 and token_list not yet allocated when the out code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);
Quoted 16 lines
Quoted 16 lines
Reported-by Coverity CID 313547
Fixes ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")
---
  fs/squashfs/sqfs.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
fs/squashfs/sqfs.c +0 -0
index 608a2bb454c..c47046b76e5 100644
@@ -949,8 +949,9 @@ int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp)
  	*dirsp = (struct fs_dir_stream *)dirs;
 
Quoted 13 lines

fs/squashfs/sqfs.c int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp) · line 957

Quoted 9 lines
fs/squashfs/sqfs.c +3 -2
  out:
-	for (j = 0; j < token_count; j++)
-		free(token_list[j]);
+	if (token_list)
+		for (j = 0; j < token_count; j++)
+			free(token_list[j]);
  	free(token_list);
  	free(pos_list);
  	free(path);

Thanks,
Miqu?l

Thanks
Richard.

#3 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

Quoted 16 lines

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 10 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

Quoted 2 lines

token_count may be != 0 and token_list not yet allocated when the out code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);

I had a look at the code, the error path is clearly not correctly organized.

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

Thanks,
Miqu?l

#4 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Le 21/12/2020 ? 16:14, Miquel Raynal a ?crit?:

Quoted 29 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

Quoted 16 lines

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 10 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

Quoted 2 lines

token_count may be != 0 and token_list not yet allocated when the out code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);
Quoted 6 lines

I had a look at the code, the error path is clearly not correctly organized.

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

So you're suggesting to revert this ?
commit ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")

Quoted 4 lines

Thanks,
Miqu?l

#5 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:26:00 +0100:

Quoted 32 lines

Le 21/12/2020 ? 16:14, Miquel Raynal a ?crit?:

Quoted 31 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

Quoted 15 lines

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 9 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

token_count may be != 0 and token_list not yet allocated when the out

code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);  

I had a look at the code, the error path is clearly not correctly organized.

Quoted 6 lines
Quoted 3 lines

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

So you're suggesting to revert this ?
commit ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")

Yes (our e-mails crossed each other), I think it's best to have a well organized error path. Of course this error path is maybe faulty, in this case it must be fixed. But I personally prefer the revert + fix approach.

Thanks,
Miqu?l

#6 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Miquel,

Le 21/12/2020 ? 16:29, Miquel Raynal a ?crit?:

Quoted 41 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:26:00 +0100:

Quoted 36 lines

Le 21/12/2020 ? 16:14, Miquel Raynal a ?crit?:

Quoted 34 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

Quoted 15 lines

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 9 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

token_count may be != 0 and token_list not yet allocated when the out

code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);

I had a look at the code, the error path is clearly not correctly organized.

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

Quoted 8 lines
Quoted 2 lines

So you're suggesting to revert this ?
commit ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")

Yes (our e-mails crossed each other), I think it's best to have a well organized error path. Of course this error path is maybe faulty, in this case it must be fixed. But I personally prefer the revert + fix approach.

But I really don't see why it's obscure to test a pointer before dereference. Maybe I should I've wrote :

        if (token_list != NULL)
                for (j = 0; j < token_count; j++)
                        free(token_list[j]);

Does it looks better ?

Quoted 3 lines

Thanks,
Miqu?l

Thanks!

#7 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:40:51 +0100:

Quoted 46 lines

Hi Miquel,

Le 21/12/2020 ? 16:29, Miquel Raynal a ?crit?:

Quoted 43 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:26:00 +0100:

Quoted 37 lines

Le 21/12/2020 ? 16:14, Miquel Raynal a ?crit?:

Quoted 27 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 9 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

token_count may be != 0 and token_list not yet allocated when the out

code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);  
Quoted 6 lines

I had a look at the code, the error path is clearly not correctly organized.

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

So you're suggesting to revert this ?
commit ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")

Quoted 7 lines
Quoted 5 lines

Yes (our e-mails crossed each other), I think it's best to have a well organized error path. Of course this error path is maybe faulty, in this case it must be fixed. But I personally prefer the revert + fix approach.

But I really don't see why it's obscure to test a pointer before dereference.

Testing a pointer before dereference is not obscure.

Testing a pointer in an error path because the error path is common to all 10 different possible failure cases and might free the content of an array that has not been allocated yet: this is obscure.

Quoted 6 lines

Maybe I should I've wrote :

        if (token_list != NULL)
                for (j = 0; j < token_count; j++)
                        free(token_list[j]);

Does it looks better ?

Not really :)

Thanks,
Miqu?l

#8 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Miquel

Le 21/12/2020 ? 16:49, Miquel Raynal a ?crit?:

Quoted 65 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:40:51 +0100:

Quoted 46 lines

Hi Miquel,

Le 21/12/2020 ? 16:29, Miquel Raynal a ?crit?:

Quoted 43 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:26:00 +0100:

Quoted 37 lines

Le 21/12/2020 ? 16:14, Miquel Raynal a ?crit?:

Quoted 27 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 9 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

     >>>> token_count may be != 0 and token_list not yet allocated when the out
Quoted 1 line

code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);
Quoted 6 lines

I had a look at the code, the error path is clearly not correctly organized.

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

So you're suggesting to revert this ?
commit ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")

Quoted 7 lines
Quoted 5 lines

Yes (our e-mails crossed each other), I think it's best to have a well organized error path. Of course this error path is maybe faulty, in this case it must be fixed. But I personally prefer the revert + fix approach.

But I really don't see why it's obscure to test a pointer before dereference.

Testing a pointer before dereference is not obscure.

Testing a pointer in an error path because the error path is common to all 10 different possible failure cases and might free the content of an array that has not been allocated yet: this is obscure.

Quoted 8 lines
Quoted 6 lines

Maybe I should I've wrote :

         if (token_list != NULL)
                 for (j = 0; j < token_count; j++)
                         free(token_list[j]);

Does it looks better ?

Not really :)

Ok, so if you insist, I send the revert correcting the coverity issue.

But in this case, the error management won't be coherent with the rest of the file. (And I *really* don't want to revert to the old error handling for every single function.)

Richard.

#9 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 17:17:56 +0100:

Quoted 71 lines

Hi Miquel

Le 21/12/2020 ? 16:49, Miquel Raynal a ?crit?:

Quoted 68 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:40:51 +0100:

Quoted 45 lines

Hi Miquel,

Le 21/12/2020 ? 16:29, Miquel Raynal a ?crit?:

Quoted 42 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:26:00 +0100:

Quoted 37 lines
Quoted 28 lines
Quoted 1 line
Quoted 1 line

Le 21/12/2020 ? 16:14, Miquel Raynal a ?crit?:

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 9 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

     >>>> token_count may be != 0 and token_list not yet allocated when the out  
Quoted 1 line

code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);  
Quoted 6 lines

I had a look at the code, the error path is clearly not correctly organized.

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

So you're suggesting to revert this ?
commit ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")

Quoted 6 lines
Quoted 5 lines

Yes (our e-mails crossed each other), I think it's best to have a well organized error path. Of course this error path is maybe faulty, in this case it must be fixed. But I personally prefer the revert + fix approach.

Quoted 1 line
Quoted 1 line

But I really don't see why it's obscure to test a pointer before dereference.

Testing a pointer before dereference is not obscure.

Testing a pointer in an error path because the error path is common to all 10 different possible failure cases and might free the content of an array that has not been allocated yet: this is obscure.

Quoted 5 lines

Maybe I should I've wrote :

         if (token_list != NULL)
                 for (j = 0; j < token_count; j++)
                         free(token_list[j]);
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Does it looks better ?

Not really :)

Ok, so if you insist, I send the revert correcting the coverity issue.

But in this case, the error management won't be coherent with the rest of the file. (And I *really* don't want to revert to the old error handling for every single function.)

Well, I was against taking this direction from the beginning, now we are at a point where the error path must be fixed because you need to take extra precautions that you would have avoided by keeping the well organized labels.

Thanks,
Miqu?l

#10 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

Hi Miquel
Le 22/12/2020 ? 08:46, Miquel Raynal a ?crit?:

Quoted 82 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 17:17:56 +0100:

Quoted 77 lines

Hi Miquel

Le 21/12/2020 ? 16:49, Miquel Raynal a ?crit?:

Quoted 63 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:40:51 +0100:

Quoted 45 lines

Hi Miquel,

Le 21/12/2020 ? 16:29, Miquel Raynal a ?crit?:

Quoted 42 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:26:00 +0100:

Quoted 37 lines
Quoted 28 lines
Quoted 1 line
Quoted 1 line

Le 21/12/2020 ? 16:14, Miquel Raynal a ?crit?:

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

     >>>> Hi Miquel,
Quoted 14 lines

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 9 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

      >>>> token_count may be != 0 and token_list not yet allocated when the out
Quoted 1 line

code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);
Quoted 6 lines

I had a look at the code, the error path is clearly not correctly organized.

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

So you're suggesting to revert this ?
commit ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling")

Quoted 6 lines
Quoted 5 lines

Yes (our e-mails crossed each other), I think it's best to have a well organized error path. Of course this error path is maybe faulty, in this case it must be fixed. But I personally prefer the revert + fix approach.

Quoted 1 line
Quoted 1 line

But I really don't see why it's obscure to test a pointer before dereference.

Testing a pointer before dereference is not obscure.

Testing a pointer in an error path because the error path is common to all 10 different possible failure cases and might free the content of an array that has not been allocated yet: this is obscure.

Quoted 8 lines
Quoted 6 lines

Maybe I should I've wrote :

          if (token_list != NULL)
                  for (j = 0; j < token_count; j++)
                          free(token_list[j]);

Does it looks better ?

Not really :)

Ok, so if you insist, I send the revert correcting the coverity issue.

Quoted 7 lines
Quoted 2 lines

But in this case, the error management won't be coherent with the rest of the file. (And I *really* don't want to revert to the old error handling for every single function.)

Well, I was against taking this direction from the beginning, now we are at a point where the error path must be fixed because you need to take extra precautions that you would have avoided by keeping the well organized labels.

Ok, let's agree to disagree.
You have a strong opinion on your way to do things, and so do I.

No need to give me the "I told you so" card here, because it won't help in anyway.

Quoted 4 lines

Thanks,
Miqu?l

Regards,
Richard

#11 lore raw

PATCH 1/1 fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir()

In reply to Miquel Raynal

Miquel Raynal <[email protected]> wrote on Mon, 21 Dec 2020 16:14:19 +0100:

Quoted 29 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Mon, 21 Dec 2020 16:06:37 +0100:

Quoted 16 lines

Hi Miquel,

Le 18/12/2020 ? 19:50, Miquel Raynal a ?crit?:

Quoted 10 lines

Hi Richard,

Richard Genoud <[email protected]> wrote on Fri, 18 Dec 2020 15:24:40 +0100:

Quoted 2 lines

token_count may be != 0 and token_list not yet allocated when the out code is reached

Wouldn't it be better to initialize token_count than adding an (obscure) indentation level?

Well, token_count is initialized :
token_count = sqfs_count_tokens(filename);

Quoted 7 lines

But token_list is not yet populated. It is some lines bellow:
token_list = malloc(token_count * sizeof(char *));

But I could use something like that, maybe it's clearer :

	for (j = 0; (token_list != NULL) && (j < token_count); j++)
		free(token_list[j]);  
Quoted 6 lines

I had a look at the code, the error path is clearly not correctly organized.

I think the right approach would be to have real labels like, free_token_list, free_this, free_that and for each of them only do the right cleanup. Doing so should fix the issue.

Actually I remember now: I disliked your proposal of changing all named labels to a single (and quite unclear) "goto out". This is an example of why single labels should not be used IMHO.

Thanks,
Miqu?l