Re: [PATCHv4] modpost: fixed resource leak in report_sec_mismatch()

Previous thread: Re: [PATCH 2/2] MEMSTICK: Add driver for Ricoh R5C592 Card reader. by Alex Dubov on Thursday, August 5, 2010 - 4:48 am. (3 messages)

Next thread: [PATCH] timekeeping: Fix overflow in rawtime tv_nsec on 32 bit archs by Jason Wessel on Thursday, August 5, 2010 - 5:28 am. (3 messages)
From: Alexey Fomenko
Date: Thursday, August 5, 2010 - 5:09 am

Patch modified for released 2.6.35 kernel. 
sec2annotation returns malloc'ed buffer directly to printf as an
argument. Patch lets free this buffer after printing. 


From: Andy Shevchenko
Date: Tuesday, August 10, 2010 - 2:14 am

On Thu, Aug 5, 2010 at 3:09 PM, Alexey Fomenko

Needs to be amended.
I told Alexey in private to resend new version of the patch.

-- 
With Best Regards,
Andy Shevchenko
--

From: Alexey Fomenko
Date: Tuesday, August 10, 2010 - 3:52 am

From: Alexey Fomenko <ext-alexey.fomenko@nokia.com>

sec2annotation() returns malloc'ed buffer directly to printf as an
argument. Patch lets free this buffer after printing. Preventing ops
while freeing the buffer by changing return const str to return 
strdup empty line.

Signed-off-by: Alexey Fomenko <ext-alexey.fomenko@nokia.com>
---
 scripts/mod/modpost.c |   58 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 16 deletions(-)

diff -ur linux-2.6.35/scripts/mod/modpost.c linux-2.6.35_b/scripts/mod/modpost.c
--- linux-2.6.35/scripts/mod/modpost.c	2010-08-10 12:11:03.854528620 +0300
+++ linux-2.6.35_b/scripts/mod/modpost.c	2010-08-10 12:11:25.174529109 +0300
@@ -1165,9 +1165,9 @@
 			strcat(p, "data ");
 		else
 			strcat(p, " ");
-		return r; /* we leak her but we do not care */
+		return r; 
 	} else {
-		return "";
+		return strdup("");
 	}
 }
 
@@ -1195,6 +1195,8 @@
 {
 	const char *from, *from_p;
 	const char *to, *to_p;
+	char *prl_from;
+	char *prl_to;
 
 
 	switch (from_is_func) {
@@ -1219,16 +1221,21 @@
 
 	switch (mismatch->mismatch) {
 	case TEXT_TO_ANY_INIT:
+		prl_from = sec2annotation(fromsec);
+		prl_to = sec2annotation(tosec);
 		fprintf(stderr,
 		"The function %s%s() references\n"
 		"the %s %s%s%s.\n"
 		"This is often because %s lacks a %s\n"
 		"annotation or the annotation of %s is wrong.\n",
-		sec2annotation(fromsec), fromsym,
-		to, sec2annotation(tosec), tosym, to_p,
-		fromsym, sec2annotation(tosec), tosym);
+		prl_from, fromsym,
+		to, prl_to, tosym, to_p,
+		fromsym, prl_to, tosym);
+		free(prl_from);
+		free(prl_to);
 		break;
 	case DATA_TO_ANY_INIT: {
+		prl_to = sec2annotation(tosec);
 		const char *const *s = mismatch->symbol_white_list;
 		fprintf(stderr,
 		"The variable %s references\n"
@@ -1236,20 +1243,24 @@
 		"If the reference is valid then annotate the\n"
 		"variable with __init* or __refdata (see linux/init.h) "
 		"or name the variable:\n",
-		fromsym, to, ...
From: Andy Shevchenko
Date: Tuesday, August 10, 2010 - 4:35 am

On Tue, Aug 10, 2010 at 1:52 PM, Alexey Fomenko
^^^^^^^^^^^^^^^^^^^^^^ missed change


Acked-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
(after fixing above issues)

-- 
With Best Regards,
Andy Shevchenko
--

From: Alexey Fomenko
Date: Tuesday, August 10, 2010 - 5:03 am

From: Alexey Fomenko <ext-alexey.fomenko@nokia.com>

sec2annotation() returns malloc'ed buffer directly to printf as an
argument. Patch lets free this buffer after printing. Preventing ops
while freeing the buffer by changing return const str to return 
strdup empty line.

Signed-off-by: Alexey Fomenko <ext-alexey.fomenko@nokia.com>
---
 scripts/mod/modpost.c |   62 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 43 insertions(+), 19 deletions(-)

diff -ur linux-2.6.35/scripts/mod/modpost.c linux-2.6.35_b/scripts/mod/modpost.c
--- linux-2.6.35/scripts/mod/modpost.c	2010-08-10 12:11:03.854528620 +0300
+++ linux-2.6.35_b/scripts/mod/modpost.c	2010-08-10 14:45:00.294529178 +0300
@@ -1165,9 +1165,9 @@
 			strcat(p, "data ");
 		else
 			strcat(p, " ");
-		return r; /* we leak her but we do not care */
+		return r;
 	} else {
-		return "";
+		return strdup("");
 	}
 }
 
@@ -1195,6 +1195,8 @@
 {
 	const char *from, *from_p;
 	const char *to, *to_p;
+	char *prl_from;
+	char *prl_to;
 
 
 	switch (from_is_func) {
@@ -1219,16 +1221,21 @@
 
 	switch (mismatch->mismatch) {
 	case TEXT_TO_ANY_INIT:
+		prl_from = sec2annotation(fromsec);
+		prl_to = sec2annotation(tosec);
 		fprintf(stderr,
 		"The function %s%s() references\n"
 		"the %s %s%s%s.\n"
 		"This is often because %s lacks a %s\n"
 		"annotation or the annotation of %s is wrong.\n",
-		sec2annotation(fromsec), fromsym,
-		to, sec2annotation(tosec), tosym, to_p,
-		fromsym, sec2annotation(tosec), tosym);
+		prl_from, fromsym,
+		to, prl_to, tosym, to_p,
+		fromsym, prl_to, tosym);
+		free(prl_from);
+		free(prl_to);
 		break;
 	case DATA_TO_ANY_INIT: {
+		prl_to = sec2annotation(tosec);
 		const char *const *s = mismatch->symbol_white_list;
 		fprintf(stderr,
 		"The variable %s references\n"
@@ -1236,20 +1243,24 @@
 		"If the reference is valid then annotate the\n"
 		"variable with __init* or __refdata (see linux/init.h) "
 		"or name the variable:\n",
-		fromsym, to, ...
From: Andy Shevchenko
Date: Tuesday, August 10, 2010 - 5:21 am

On Tue, Aug 10, 2010 at 3:03 PM, Alexey Fomenko
Did you ever compile this code?

-- 
With Best Regards,
Andy Shevchenko
--

From: Alexey Fomenko
Date: Tuesday, August 10, 2010 - 5:40 am

Ever - yes, last one - no, was in a hurry. Shouldn't have been.


--

From: Andy Shevchenko
Date: Tuesday, August 10, 2010 - 6:43 am

On Tue, Aug 10, 2010 at 4:09 PM, Alexey Fomenko

Now seems fine to me.

Reviewed-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>


-- 
With Best Regards,
Andy Shevchenko
--

Previous thread: Re: [PATCH 2/2] MEMSTICK: Add driver for Ricoh R5C592 Card reader. by Alex Dubov on Thursday, August 5, 2010 - 4:48 am. (3 messages)

Next thread: [PATCH] timekeeping: Fix overflow in rawtime tv_nsec on 32 bit archs by Jason Wessel on Thursday, August 5, 2010 - 5:28 am. (3 messages)