public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Brian Foster <brian.foster@maxim-ic.com>,
	Brian Norris <computersforpeace@gmail.com>,
	linux-mtd@lists.infradead.org
Subject: [PATCH 2/3] libmtd: fix segmentation fault on lib->mtd
Date: Thu,  9 Feb 2012 10:13:30 -0800	[thread overview]
Message-ID: <1328811211-13653-3-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1328811211-13653-1-git-send-email-computersforpeace@gmail.com>

Legacy systems do not initialize lib->mtd, so we shouldn't perform
strlen(lib->mtd); this produces a segmentation fault. As this code isn't
used in the legacy codepath, we can just move it down to an 'else' branch.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 lib/libmtd.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/libmtd.c b/lib/libmtd.c
index 2bb4e57..fb4586c 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -644,13 +644,15 @@ void libmtd_close(libmtd_t desc)
 int mtd_dev_present(libmtd_t desc, int mtd_num) {
 	struct stat st;
 	struct libmtd *lib = (struct libmtd *)desc;
-	char file[strlen(lib->mtd) + 10];
 
 	if (!lib->sysfs_supported)
 		return legacy_dev_present(mtd_num);
+	else {
+		char file[strlen(lib->mtd) + 10];
 
-	sprintf(file, lib->mtd, mtd_num);
-	return !stat(file, &st);
+		sprintf(file, lib->mtd, mtd_num);
+		return !stat(file, &st);
+	}
 }
 
 int mtd_get_info(libmtd_t desc, struct mtd_info *info)
-- 
1.7.5.4

  parent reply	other threads:[~2012-02-09 18:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-09 18:13 [PATCH 0/3] mtdinfo fixes (--all, etc.) Brian Norris
2012-02-09 18:13 ` [PATCH 1/3] limbtd: implement mtd_dev_present for old kernels Brian Norris
2012-02-09 18:13 ` Brian Norris [this message]
2012-02-09 18:13 ` [PATCH 3/3] mtdinfo: correct grammar on error message Brian Norris

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=1328811211-13653-3-git-send-email-computersforpeace@gmail.com \
    --to=computersforpeace@gmail.com \
    --cc=brian.foster@maxim-ic.com \
    --cc=dedekind1@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    /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