mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daeseok Youn <daeseok.youn@gmail.com>
To: lidza.louina@gmail.com
Cc: markh@compro.net, daeseok.youn@gmail.com,
	gregkh@linuxfoundation.org,
	driverdev-devel@linuxdriverproject.org,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH 8/8] staging: dgap: fix memory leak in dgap_parsefile()
Date: Tue, 15 Jul 2014 12:05:14 +0900	[thread overview]
Message-ID: <20140715030456.GA14420@devel.8.8.4.4> (raw)

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().

Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
---
 drivers/staging/dgap/dgap.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index a207bd7..cedf4b3 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -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);
-- 
1.7.1


             reply	other threads:[~2014-07-15  3:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-15  3:05 Daeseok Youn [this message]
2014-07-15  6:51 ` Dan Carpenter
2014-07-15  9:05   ` DaeSeok Youn
2014-07-15  9:21     ` Dan Carpenter
2014-07-15  9:45       ` DaeSeok Youn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140715030456.GA14420@devel.8.8.4.4 \
    --to=daeseok.youn@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lidza.louina@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markh@compro.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®