aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2012-02-09 10:13:30 -0800
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-02-14 11:00:12 +0200
commit6571ef822aa7d782a8168d39a27fa3e65a3032be (patch)
tree274560723694736b3f0d13fddd77cc5a20537b11 /lib
parenteded3cd0a52252f677ceacd1fbcae13be3d55e8f (diff)
libmtd: fix segmentation fault on lib->mtd
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> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/libmtd.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libmtd.c b/lib/libmtd.c
index ecf182f..f0d40a0 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)