[gparted] Fix crash reading NTFS usage when there is no /dev/PTN entry (#764658)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Fix crash reading NTFS usage when there is no /dev/PTN entry (#764658)
- Date: Thu, 7 Apr 2016 15:59:28 +0000 (UTC)
commit 366152e4499fce4560e9889489fca8b42c5f67d0
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Mon Apr 4 16:28:16 2016 +0100
Fix crash reading NTFS usage when there is no /dev/PTN entry (#764658)
On a 64-bit distribution, with an NTFS file system in a partition
without a /dev entry then GParted will crash when attempting to read
the file system usage. Not having a /dev entry for the partition is
rare and only known to occur for the disk devices used within Fake RAID
(dmraid) arrays, and then only on Ubuntu 12.04 LTS. Other/newer
distributions do create /dev entries for partitions found on disk
devices within Fake RAID arrays.
Create mirror Fake RAID array:
# dmraid -f isw -C MyArray --type 1 --disk /dev/sdc,/dev/sdd
# dmraid -ay
Create NTFS partition on the Fake RAID array. On refresh GParted
crashes:
# ./gpartedbin
(gpartedbin:590): glibmm-ERROR **:
unhandled exception (type std::exception) in signal handler:
what: basic_string::assign
Without a /dev/sdc1 device entry the ntfsresize command reports this:
# ntfsresize --info --force --no-progress-bar /dev/sdc1
ntfsresize v2015.3.14 (libntfs-3g)
ERROR(2): Failed to check '/dev/sdc1' mount state: No such file or directory
Probably /etc/mtab is missing. It's too risky to continue. You might try
an another Linux distro.
The problem code in ntfs::set_used_sectors():
145 index = output.find( "Cluster size" );
146 if ( index == output.npos ||
147 sscanf( output.substr( index ).c_str(), "Cluster size : %Ld", &S ) != 1 )
As "Cluster size" did not exist in the output find() returned the not
found token of string::npos [1], which in a 64-bit environment is
represented by 2^64-1 [2]. However it was saved in the variable index
of type unsigned integer, which is only a 32-bit integer, thus
truncating it to 2^32-1. Therefore the comparison failed and sscanf()
tried to parse the output starting at offset 2^32-1 which resulted in
the crash.
Introduced by commit:
324d99a172848e4ff3fb7eb189f490bb4e6c53e5
Record file system block size where known (#760709)
Fix by following the same pattern of the other comparisons in
ntfs::set_used_sectors() which checks if index is less than the output
length.
References:
[1] std::string::find
http://www.cplusplus.com/reference/string/string/find/
[2] std::string::npos
http://www.cplusplus.com/reference/string/string/npos/
(Note that Glib::ustring is derived from std::string in the Standard C++
library and provides a compatible interface).
Bug 764658 - GParted crashes when reading NTFS usage when there is no
/dev/PTN entry
src/ntfs.cc | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/src/ntfs.cc b/src/ntfs.cc
index 0d46d24..50716be 100644
--- a/src/ntfs.cc
+++ b/src/ntfs.cc
@@ -143,7 +143,7 @@ void ntfs::set_used_sectors( Partition & partition )
N = T ;
index = output.find( "Cluster size" );
- if ( index == output.npos ||
+ if ( index >= output.length() ||
sscanf( output.substr( index ).c_str(), "Cluster size : %Ld", &S ) != 1 )
S = -1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]