Skip to contentSkip to conversation

staging: greybus: loop variable to loop index

PATCH In review Gargi Sharma 3 participants 5 messages Feb 21, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: greybus: loop variable to loop index

Change array index from the loop bound variable to loop index. Once all the loopback devices have been found, free the pointer array containing the dirent structures. The pointer to dirent structures must be individually freed before freeing the pointer array.

Coccinelle Script:
@@
expression arr,ex1,ex2;
@@

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

---
 drivers/staging/greybus/tools/loopback_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/tools/loopback_test.c +1 -1
index 18d7a3d..1c01833 100644
@@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
 	ret = 0;
 done:
 	for (i = 0; i < n; i++)
-		free(namelist[n]);
+		free(namelist[i]);
 	free(namelist);
 baddir:
 	return ret;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 28 lines · Gargi Sharma

Change array index from the loop bound variable to loop index. Once all the loopback devices have been found, free the pointer array containing the dirent structures. The pointer to dirent structures must be individually freed before freeing the pointer array.

Coccinelle Script:
@@
expression arr,ex1,ex2;
@@

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

---
 drivers/staging/greybus/tools/loopback_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/tools/loopback_test.c +0 -0
index 18d7a3d..1c01833 100644

drivers/staging/greybus/tools/loopback_test.c int find_loopback_devices(struct loopback_test *t) · line 639

Quoted 5 lines
drivers/staging/greybus/tools/loopback_test.c +1 -1
@@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
 	ret = 0;
 done:
 	for (i = 0; i < n; i++)
-		free(namelist[n]);
+		free(namelist[i]);

I guess this is a test, so no one ever tried running it :)

julia

Quoted 13 lines
drivers/staging/greybus/tools/loopback_test.c +0 -1
 	free(namelist);
 baddir:
 	return ret;
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1487696353-11316-1-git-send-email-gs051095%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

maintainer
#2 lore raw
Quoted 13 lines · Julia Lawall
Quoted 11 lines · Gargi Sharma

Change array index from the loop bound variable to loop index. Once all the loopback devices have been found, free the pointer array containing the dirent structures. The pointer to dirent structures must be individually freed before freeing the pointer array.

Coccinelle Script:
@@
expression arr,ex1,ex2;
@@

Quoted 6 lines
Quoted 6 lines

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

Another good catch, but you should change the patch summary to something more descriptive (and less detailed) like:

staging: greybus: loopback_test: fix device-name leak

and possibly also make it more clear from the commit message that we've been leaking these strings whenever there have been more than one loopback device. (The memory is returned once the test program exits, but still).

Care to send a v2 with those changes?

Quoted 5 lines
Quoted 5 lines
---
 drivers/staging/greybus/tools/loopback_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/staging/greybus/tools/loopback_test.c int find_loopback_devices(struct loopback_test *t) · line 639

Quoted 10 lines
drivers/staging/greybus/tools/loopback_test.c +1 -1
index 18d7a3d..1c01833 100644
@@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
 	ret = 0;
 done:
 	for (i = 0; i < n; i++)
-		free(namelist[n]);
+		free(namelist[i]);

I guess this is a test, so no one ever tried running it :)

It is a test tool, but we've been using it quite a bit.

Thanks,
Johan

#3 lore raw
Quoted 51 lines · Johan Hovold
Quoted 13 lines · Julia Lawall
Quoted 11 lines · Gargi Sharma

Change array index from the loop bound variable to loop index. Once all the loopback devices have been found, free the pointer array containing the dirent structures. The pointer to dirent structures must be individually freed before freeing the pointer array.

Coccinelle Script:
@@
expression arr,ex1,ex2;
@@

Quoted 6 lines
Quoted 6 lines

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

Another good catch, but you should change the patch summary to something more descriptive (and less detailed) like:

staging: greybus: loopback_test: fix device-name leak

and possibly also make it more clear from the commit message that we've been leaking these strings whenever there have been more than one loopback device. (The memory is returned once the test program exits, but still).

Care to send a v2 with those changes?

Quoted 5 lines
Quoted 5 lines
---
 drivers/staging/greybus/tools/loopback_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/staging/greybus/tools/loopback_test.c int find_loopback_devices(struct loopback_test *t) · line 639

Quoted 10 lines
drivers/staging/greybus/tools/loopback_test.c +1 -1
index 18d7a3d..1c01833 100644
@@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
 	ret = 0;
 done:
 	for (i = 0; i < n; i++)
-		free(namelist[n]);
+		free(namelist[i]);

I guess this is a test, so no one ever tried running it :)

Quoted 1 line

It is a test tool, but we've been using it quite a bit.

I guess I don't know what n is. I would have expected that it would be an out of bounds array reference, at least sometimes.

julia

Quoted 11 lines

Thanks,
Johan

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170221181950.GD10245%40localhost.
For more options, visit https://groups.google.com/d/optout.

maintainer
#4 lore raw
Quoted 52 lines · Julia Lawall
Quoted 51 lines · Johan Hovold
Quoted 13 lines · Julia Lawall
Quoted 11 lines · Gargi Sharma

Change array index from the loop bound variable to loop index. Once all the loopback devices have been found, free the pointer array containing the dirent structures. The pointer to dirent structures must be individually freed before freeing the pointer array.

Coccinelle Script:
@@
expression arr,ex1,ex2;
@@

Quoted 6 lines
Quoted 6 lines

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

Another good catch, but you should change the patch summary to something more descriptive (and less detailed) like:

staging: greybus: loopback_test: fix device-name leak

and possibly also make it more clear from the commit message that we've been leaking these strings whenever there have been more than one loopback device. (The memory is returned once the test program exits, but still).

Care to send a v2 with those changes?

Quoted 17 lines
Quoted 10 lines
---
 drivers/staging/greybus/tools/loopback_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/tools/loopback_test.c +0 -0
index 18d7a3d..1c01833 100644

drivers/staging/greybus/tools/loopback_test.c int find_loopback_devices(struct loopback_test *t) · line 639

Quoted 5 lines
drivers/staging/greybus/tools/loopback_test.c +1 -1
@@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
 	ret = 0;
 done:
 	for (i = 0; i < n; i++)
-		free(namelist[n]);
+		free(namelist[i]);

I guess this is a test, so no one ever tried running it :)

Quoted 4 lines
Quoted 1 line

It is a test tool, but we've been using it quite a bit.

I guess I don't know what n is. I would have expected that it would be an out of bounds array reference, at least sometimes.

No, you're absolutely right, I just noticed the potential illegal free here too. Perhaps namelist[n] has just happened to be NULL so far.

Thanks,
Johan