Skip to contentSkip to conversation

staging: dgap: fix memory leak in dgap_parsefile()

PATCH Superseded Daeseok Youn 2 participants 5 messages Jul 15, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 8/8 staging: dgap: fix memory leak in dgap_parsefile()

The p->u.board.status is allocated and set a string as "No" once within allocating a node of BNODE type. But it also set again with kstrdup() in case of "STATUS" or "ID". If it is not allocated yet, use kstrdup(). If not, use just memcpy().

---
 drivers/staging/dgap/dgap.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
drivers/staging/dgap/dgap.c +9 -2
index a207bd7..cedf4b3 100644
@@ -6598,7 +6598,11 @@ static int dgap_parsefile(char **in)
 				pr_err("dgap: parse: unexpected end of file\n");
 				return -1;
 			}
-			p->u.board.status = kstrdup(s, GFP_KERNEL);
+
+			if (p->u.board.status)
+				memcpy(p->u.board.status, s, strlen(s) + 1);
+			else
+				p->u.board.status = kstrdup(s, GFP_KERNEL);
 			break;
 
 		case NPORTS:	/* number of ports */
@@ -6648,7 +6652,10 @@ static int dgap_parsefile(char **in)
 				return -1;
 			}
 
-			p->u.board.status = kstrdup(s, GFP_KERNEL);
+			if (p->u.board.status)
+				memcpy(p->u.board.status, s, strlen(s) + 1);
+			else
+				p->u.board.status = kstrdup(s, GFP_KERNEL);
 
 			if (p->type == CNODE) {
 				p->u.conc.id = kstrdup(s, GFP_KERNEL);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 5 lines · Daeseok Youn

The p->u.board.status is allocated and set a string as "No" once within allocating a node of BNODE type. But it also set again with kstrdup() in case of "STATUS" or "ID". If it is not allocated yet, use kstrdup(). If not, use just memcpy().

I don't think a 2 char buffer is always large enough to hold the new strings.

Just free it and allocate again.

regards,
dan carpenter

#2 lore raw

2014-07-15 15:51 GMT+09:00 Dan Carpenter <[email protected]>:

Quoted 11 lines · Daeseok Youn
Quoted 5 lines

The p->u.board.status is allocated and set a string as "No" once within allocating a node of BNODE type. But it also set again with kstrdup() in case of "STATUS" or "ID". If it is not allocated yet, use kstrdup(). If not, use just memcpy().

I don't think a 2 char buffer is always large enough to hold the new strings.

Just free it and allocate again.

Yes, I will send this again.

Thanks.

regards,
Daeseok Youn.

Quoted 4 lines

regards,
dan carpenter

#3 lore raw
Quoted 8 lines · DaeSeok Youn

2014-07-15 15:51 GMT+09:00 Dan Carpenter <[email protected]>:

Quoted 7 lines · Daeseok Youn
Quoted 5 lines

The p->u.board.status is allocated and set a string as "No" once within allocating a node of BNODE type. But it also set again with kstrdup() in case of "STATUS" or "ID". If it is not allocated yet, use kstrdup(). If not, use just memcpy().

Quoted 6 lines
Quoted 4 lines

I don't think a 2 char buffer is always large enough to hold the new strings.

Just free it and allocate again.

Yes, I will send this again.

Actually, please just send the whole set again. I really want Mark on the CC list so he's reviewing these.

regards,
dan carpenter

#4 lore raw

2014-07-15 18:21 GMT+09:00 Dan Carpenter <[email protected]>:

Quoted 12 lines · DaeSeok Youn
Quoted 11 lines

2014-07-15 15:51 GMT+09:00 Dan Carpenter <[email protected]>:

Quoted 10 lines · Daeseok Youn
Quoted 5 lines

The p->u.board.status is allocated and set a string as "No" once within allocating a node of BNODE type. But it also set again with kstrdup() in case of "STATUS" or "ID". If it is not allocated yet, use kstrdup(). If not, use just memcpy().

I don't think a 2 char buffer is always large enough to hold the new strings.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Just free it and allocate again.

Yes, I will send this again.

Actually, please just send the whole set again. I really want Mark on the CC list so he's reviewing these.

OK. I already sent 6/8, 7/8 and 8/8 again. I just resend rest of them.

thanks.

regards,
Daeseok Youn

Quoted 4 lines

regards,
dan carpenter