GNU bug report logs -
#15591
gpt mishandles non ascii partition names
Previous Next
Reported by: Phillip Susi <psusi <at> ubuntu.com>
Date: Fri, 11 Oct 2013 19:00:02 UTC
Severity: normal
Merged with 15597
Done: Jim Meyering <jim <at> meyering.net>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15591 in the body.
You can then email your comments to 15591 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Fri, 11 Oct 2013 19:00:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Phillip Susi <psusi <at> ubuntu.com>
:
New bug report received and forwarded. Copy sent to
bug-parted <at> gnu.org
.
(Fri, 11 Oct 2013 19:00:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Original bug report:
https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1238446
The gpt partition table has 16 bit characters for the name, which I
assume are supposed to be UTF-16, but the bloody uefi standard is moot
on the subject. Currently parted simply decimates the characters,
throwing out the upper 8 bits. This corrupts characters that aren't
simple ascii, and at some later point, strlist.c calls mbstrtowcs(),
which chokes on the corrupt name causing parted to bail out with
"Error during translation".
I think that gpt.c needs to translate the UTF-16 to the native
multibyte encoding, but I have no idea how to do that. The C standard
conversion functions all seem to use the current locale and don't have
a way to override it if you know this string is in UTF-16 ( and maybe
the current locale is UTF-8 ).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJSWEpxAAoJEJrBOlT6nu75YYYH+gOqxQdKmRmPFfSAFbkOnXzf
9SqhaamWXNmqWLCaKHb4COO0S/Wg5Uu5Kzw0chqFbty0+S+Wa13/SM97S25SxUmh
q3sVnWbVwbOW5D2NAGhC7jjGwpZ9F4k45xE4DaHntSD1lsoYfq5+D25+4h7GTNqL
vliuuFhzUs5dQke/ONFnRfDb202ZC4j+HE7nBRwRm7VsUswsiiPVV8dz5iSQhkD1
/tx3N63A9aViBpFLlgGZu8XSaBHoE+4ZZ/COEGPzga372GDXyccODe0QfmErqWKI
3s0juqk5uOhUWvrWfzaYDtFEG+3AXuIXm8OT/SEQ4uKlqpCBKsFoBQLRGvoEPOE=
=0KW9
-----END PGP SIGNATURE-----
Merged 15591 15597.
Request was from
Phillip Susi <psusi <at> ubuntu.com>
to
control <at> debbugs.gnu.org
.
(Mon, 14 Oct 2013 17:51:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Thu, 19 Dec 2013 21:26:01 GMT)
Full text and
rfc822 format available.
Message #10 received at 15591 <at> debbugs.gnu.org (full text, mbox):
gpt.c was simply truncating the UTF-16 characters stored
in the partition name field to 8 bits. This corrupted non
ascii characters which later resulted in parted crashing in
strlist.c trying to convert the now invalid multi byte
characters to wchar.
gpt.c will now properly convert the UTF-16 to the current
locale encoding.
---
libparted/labels/gpt.c | 60 ++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 53 insertions(+), 7 deletions(-)
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 490de70..73109f4 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -39,6 +39,8 @@
#include <uuid/uuid.h>
#include <stdbool.h>
#include <errno.h>
+#include <iconv.h>
+#include <langinfo.h>
#include "xalloc.h"
#include "verify.h"
@@ -192,7 +194,7 @@ struct __attribute__ ((packed)) _GuidPartitionEntry_t
uint64_t StartingLBA;
uint64_t EndingLBA;
GuidPartitionEntryAttributes_t Attributes;
- efi_char16_t PartitionName[72 / sizeof (efi_char16_t)];
+ efi_char16_t PartitionName[36];
};
#define GPT_PMBR_LBA 0
@@ -276,7 +278,8 @@ typedef struct _GPTPartitionData
{
efi_guid_t type;
efi_guid_t uuid;
- char name[37];
+ efi_char16_t name[37];
+ char *translated_name;
int lvm;
int raid;
int boot;
@@ -785,10 +788,11 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
gpt_part_data = part->disk_specific;
gpt_part_data->type = pte->PartitionTypeGuid;
gpt_part_data->uuid = pte->UniquePartitionGuid;
- for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
+ for (i = 0; i < 36; i++)
gpt_part_data->name[i] =
(efi_char16_t) PED_LE16_TO_CPU ((uint16_t) pte->PartitionName[i]);
gpt_part_data->name[i] = 0;
+ gpt_part_data->translated_name = 0;
gpt_part_data->lvm = gpt_part_data->raid
= gpt_part_data->boot = gpt_part_data->hp_service
@@ -1196,7 +1200,7 @@ _partition_generate_part_entry (PedPartition *part, GuidPartitionEntry_t *pte)
if (gpt_part_data->legacy_boot)
pte->Attributes.LegacyBIOSBootable = 1;
- for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
+ for (i = 0; i < 36; i++)
pte->PartitionName[i]
= (efi_char16_t) PED_CPU_TO_LE16 ((uint16_t) gpt_part_data->name[i]);
}
@@ -1371,6 +1375,8 @@ gpt_partition_duplicate (const PedPartition *part)
goto error_free_part;
*result_data = *part_data;
+ if (part_data->translated_name)
+ result_data->translated_name = strdup (part_data->translated_name);
return result;
error_free_part:
@@ -1385,6 +1391,8 @@ gpt_partition_destroy (PedPartition *part)
if (part->type == 0)
{
PED_ASSERT (part->disk_specific != NULL);
+ GPTPartitionData *gpt_part_data = part->disk_specific;
+ free (gpt_part_data->translated_name);
free (part->disk_specific);
}
@@ -1776,15 +1784,53 @@ gpt_partition_set_name (PedPartition *part, const char *name)
{
GPTPartitionData *gpt_part_data = part->disk_specific;
- strncpy (gpt_part_data->name, name, 36);
- gpt_part_data->name[36] = 0;
+ free(gpt_part_data->translated_name);
+ gpt_part_data->translated_name = strdup(name);
+ iconv_t conv = iconv_open ("UTF-16", nl_langinfo (CODESET));
+ if (conv == (iconv_t)-1)
+ goto err;
+ char *inbuff = gpt_part_data->translated_name;
+ char *outbuff = (char *)&gpt_part_data->name;
+ size_t inbuffsize = strlen (inbuff);
+ size_t outbuffsize = 72;
+ if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
+ goto err;
+ iconv_close (conv);
+ return;
+ err:
+ ped_exception_throw (PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
+ iconv_close (conv);
}
static const char *
gpt_partition_get_name (const PedPartition *part)
{
GPTPartitionData *gpt_part_data = part->disk_specific;
- return gpt_part_data->name;
+ if (gpt_part_data->translated_name == NULL)
+ {
+ char buffer[200];
+ iconv_t conv = iconv_open (nl_langinfo (CODESET), "UTF-16");
+ if (conv == (iconv_t)-1)
+ goto err;
+ char *inbuff = (char *)&gpt_part_data->name;
+ char *outbuff = buffer;
+ size_t inbuffsize = 72;
+ size_t outbuffsize = sizeof(buffer);
+ if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
+ goto err;
+ iconv_close (conv);
+ *outbuff = 0;
+ gpt_part_data->translated_name = strdup (buffer);
+ return gpt_part_data->translated_name;
+ err:
+ ped_exception_throw (PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
+ iconv_close (conv);
+ }
+ return gpt_part_data->translated_name;
}
static int
--
1.8.3.2
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Thu, 19 Dec 2013 22:15:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 15591 <at> debbugs.gnu.org (full text, mbox):
On Thu, Dec 19, 2013 at 1:25 PM, Phillip Susi <psusi <at> ubuntu.com> wrote:
> gpt.c was simply truncating the UTF-16 characters stored
> in the partition name field to 8 bits. This corrupted non
> ascii characters which later resulted in parted crashing in
> strlist.c trying to convert the now invalid multi byte
> characters to wchar.
>
> gpt.c will now properly convert the UTF-16 to the current
> locale encoding.
Hi Philip,
Thanks for fixing that. Your patch looks good.
One nit:
> + gpt_part_data->translated_name = strdup(name);
Would you please adjust that to handle strdup failure?
Perhaps just by using xstrdup in place of strdup.
Also, it'd be great to add a test case that fails without this fix?
Thanks,
Jim
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Thu, 19 Dec 2013 22:15:03 GMT)
Full text and
rfc822 format available.
Message #16 received at 15591 <at> debbugs.gnu.org (full text, mbox):
Oh, and since this is a bug fix, it deserves mention in NEWS.
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Fri, 20 Dec 2013 02:06:02 GMT)
Full text and
rfc822 format available.
Message #19 received at 15591 <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
On 12/19/2013 05:13 PM, Jim Meyering wrote:
> Also, it'd be great to add a test case that fails without this
> fix?
I can create a partition table using a unicode name, but can I include
an arbitrary binary image in the test suite? I seem to remember the
test suite wanting to copy the shell script to its own directory to
execute it.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBCgAGBQJSs6XzAAoJEI5FoCIzSKrwDXQH/2xAWiH2DaTgVB9pRaJ8sgtt
XQ7UVFWwf3bTlw9bxh1m3hH5cLanod+tLyLaXywcCqJ24fALpOUHnXiw+sCRntuj
UGAcqDXQj37PHWoe2eQ7XWuAJEi0Fch1TRNp2+rtvaruR0FlwsdXQxvbqQotyCgu
eiBWUNGaWlHPbteCZNdwZi3NMQnwQ5w7B4S9kmIvhP90/0xLPdajzhDZOIuFRPs7
dn0nrQdOYkFFM4VRVRptGrT5+YdaZAUD1hcZJOe7NSIbZcOVoMmvD17IGehYniPA
fIte+UPF2wiBaVCrwuwQgWfkxhs6VWDLu5YTH7BY0kFcEqUKemMMMKwJvipmQlM=
=CRYw
-----END PGP SIGNATURE-----
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Fri, 20 Dec 2013 05:36:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 15591 <at> debbugs.gnu.org (full text, mbox):
On Thu, Dec 19, 2013 at 6:05 PM, Phillip Susi <psusi <at> ubuntu.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> On 12/19/2013 05:13 PM, Jim Meyering wrote:
>> Also, it'd be great to add a test case that fails without this
>> fix?
>
> I can create a partition table using a unicode name, but can I include
> an arbitrary binary image in the test suite? I seem to remember the
> test suite wanting to copy the shell script to its own directory to
> execute it.
Ideally, the script would create a partition table from scratch and
then create a partition table with a unicode name, then verify that
it can be read/displayed properly. Then there's no issue with
storing an image in git.
If you don't have the time or inclination, point me to an offending
image and I'll derive a stand-alone test that doesn't need that image.
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Fri, 20 Dec 2013 14:17:02 GMT)
Full text and
rfc822 format available.
Message #25 received at 15591 <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/20/2013 12:35 AM, Jim Meyering wrote:
> Ideally, the script would create a partition table from scratch
> and then create a partition table with a unicode name, then verify
> that it can be read/displayed properly. Then there's no issue
> with storing an image in git.
>
> If you don't have the time or inclination, point me to an
> offending image and I'll derive a stand-alone test that doesn't
> need that image.
You can create one with parted after applying the patch, or with
gdisk, and entering a unicode character in the name. Also git has no
problem with binary files; util-linux includes several bzip2'd binary
disk images for its test suite.
Note that trying to use unicode characters with parted without this
patch appears to work, since writing the string spreads it out over
multiple bytes with zeros between, and reading it back undoes this
damage. Setting the name with gdisk causes parted to puke when it
reads it.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJStFEoAAoJEI5FoCIzSKrwR60H/2Ir5tUMia+lABWgkQFD8yxO
us84cUqTUvxrCLqhZTrYIuUPYyC87LfQgDe8cYdpIS9qHY5kLH6ZlnyDdJnHTyFb
H7kyemBwwqHWS4SAzcv5ZDLvS5eDDWk/qlitbSaZweVTtmU+SoGnMv75+BpobI1P
DifugCznT1qWqGiuKOmCVIHFFoH0cKnbxoWEP3py9mGFSywhwkurTrSk+Az1Ryax
EaQlNlX7DaZHCxLcyzlvctvoFK/nnOAHAXG/y+fDVSeVnAsSzqlACQiqjyc+lomD
/4CBrG+lHBJOfmLaH+nXjA+HVhsd1PkQ4DKQX/B35Y94qAi1Z36Q/44XDJfA5eI=
=IKnB
-----END PGP SIGNATURE-----
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Fri, 20 Dec 2013 19:13:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 15591 <at> debbugs.gnu.org (full text, mbox):
On Fri, Dec 20, 2013 at 6:16 AM, Phillip Susi <psusi <at> ubuntu.com> wrote:
...
> You can create one with parted after applying the patch, or with
> gdisk, and entering a unicode character in the name. Also git has no
> problem with binary files; util-linux includes several bzip2'd binary
> disk images for its test suite.
>
> Note that trying to use unicode characters with parted without this
> patch appears to work, since writing the string spreads it out over
> multiple bytes with zeros between, and reading it back undoes this
> damage. Setting the name with gdisk causes parted to puke when it
> reads it.
Thanks for explaining. In that case, we can create a test image with
a unicode character partition name, and use dd to inspect the on-disk
bytes, looking for the desired (new) behavior. That should fail with
the pre-patch parted and succeed with the fixed version.
Sure, git can handle arbitrary files... but I have a general aversion
to storing test images in version control when there is an easy way
to avoid it.
Would you mind doing that?
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Fri, 20 Dec 2013 19:30:03 GMT)
Full text and
rfc822 format available.
Message #31 received at 15591 <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/20/2013 2:11 PM, Jim Meyering wrote:
> Thanks for explaining. In that case, we can create a test image
> with a unicode character partition name, and use dd to inspect the
> on-disk bytes, looking for the desired (new) behavior. That should
> fail with the pre-patch parted and succeed with the fixed version.
Ahh, of course, why didn't I think of that? <facepalm />
> Sure, git can handle arbitrary files... but I have a general
> aversion to storing test images in version control when there is an
> easy way to avoid it.
>
> Would you mind doing that?
I'll try to work it up tonight.
Say, if you have some time for patch reviewing these days, think you
could take a look at the online resize patch set? They have been in
Debian and Ubuntu now for a bit and the last gparted livecd is using
them, so it would be nice to finally get them applied upstream and a
new release done.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJStJqvAAoJEI5FoCIzSKrwtY0H/1bIPdZ7uiN2SYoBbyVvN3Lz
FU1oL2+uEkM7vVX+6aUcES3S29gjmjUOTUpGmLdv9QwL1gg3hD/RtRpvd7ax8GYy
NfbIi71pGBL+tPsi05h7UosGplx+8IVbSBr5cZIrrCqe3ftH0FCJb0NBhaG8dRy7
N1OuQx+RZhedt0r3X88P2yeU/JSNQJGvpFidRNRYmCDAKjJOD0DToJJKutTU/rCI
fMEQiZ8B0OU6DWSQSYF+xBecuiBnhXTLDmbikSrQrZcts7ZEGY6xychTN+i/AcUJ
bMUNeyhGYaAkXmLaSCApDqkKFHhc0kRomQkrEMnF7jSkm3r8hmFqygfVXrIiH2c=
=LCO8
-----END PGP SIGNATURE-----
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Sat, 21 Dec 2013 02:26:02 GMT)
Full text and
rfc822 format available.
Message #34 received at 15591 <at> debbugs.gnu.org (full text, mbox):
gpt.c was simply truncating the UTF-16 characters stored
in the partition name field to 8 bits. This corrupted non
ascii characters which later resulted in parted crashing in
strlist.c trying to convert the now invalid multi byte
characters to wchar.
gpt.c will now properly convert the UTF-16 to the current
locale encoding.
---
libparted/labels/gpt.c | 60 ++++++++++++++++++++++++++++++++++++++++------
tests/Makefile.am | 1 +
tests/t0251-gpt-unicode.sh | 40 +++++++++++++++++++++++++++++++
3 files changed, 94 insertions(+), 7 deletions(-)
create mode 100644 tests/t0251-gpt-unicode.sh
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 66c96e6..25007cb 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -39,6 +39,8 @@
#include <uuid/uuid.h>
#include <stdbool.h>
#include <errno.h>
+#include <iconv.h>
+#include <langinfo.h>
#include "xalloc.h"
#include "verify.h"
@@ -196,7 +198,7 @@ struct __attribute__ ((packed)) _GuidPartitionEntry_t
uint64_t StartingLBA;
uint64_t EndingLBA;
GuidPartitionEntryAttributes_t Attributes;
- efi_char16_t PartitionName[72 / sizeof (efi_char16_t)];
+ efi_char16_t PartitionName[36];
};
#define GPT_PMBR_LBA 0
@@ -281,7 +283,8 @@ typedef struct _GPTPartitionData
{
efi_guid_t type;
efi_guid_t uuid;
- char name[37];
+ efi_char16_t name[37];
+ char *translated_name;
int lvm;
int raid;
int boot;
@@ -797,10 +800,11 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
gpt_part_data = part->disk_specific;
gpt_part_data->type = pte->PartitionTypeGuid;
gpt_part_data->uuid = pte->UniquePartitionGuid;
- for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
+ for (i = 0; i < 36; i++)
gpt_part_data->name[i] =
(efi_char16_t) PED_LE16_TO_CPU ((uint16_t) pte->PartitionName[i]);
gpt_part_data->name[i] = 0;
+ gpt_part_data->translated_name = 0;
gpt_part_data->lvm = gpt_part_data->raid
= gpt_part_data->boot = gpt_part_data->hp_service
@@ -1210,7 +1214,7 @@ _partition_generate_part_entry (PedPartition *part, GuidPartitionEntry_t *pte)
if (gpt_part_data->legacy_boot)
pte->Attributes.LegacyBIOSBootable = 1;
- for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
+ for (i = 0; i < 36; i++)
pte->PartitionName[i]
= (efi_char16_t) PED_CPU_TO_LE16 ((uint16_t) gpt_part_data->name[i]);
}
@@ -1386,6 +1390,8 @@ gpt_partition_duplicate (const PedPartition *part)
goto error_free_part;
*result_data = *part_data;
+ if (part_data->translated_name)
+ result_data->translated_name = strdup (part_data->translated_name);
return result;
error_free_part:
@@ -1400,6 +1406,8 @@ gpt_partition_destroy (PedPartition *part)
if (part->type == 0)
{
PED_ASSERT (part->disk_specific != NULL);
+ GPTPartitionData *gpt_part_data = part->disk_specific;
+ free (gpt_part_data->translated_name);
free (part->disk_specific);
}
@@ -1820,15 +1828,53 @@ gpt_partition_set_name (PedPartition *part, const char *name)
{
GPTPartitionData *gpt_part_data = part->disk_specific;
- strncpy (gpt_part_data->name, name, 36);
- gpt_part_data->name[36] = 0;
+ free(gpt_part_data->translated_name);
+ gpt_part_data->translated_name = strdup(name);
+ iconv_t conv = iconv_open ("UTF-16", nl_langinfo (CODESET));
+ if (conv == (iconv_t)-1)
+ goto err;
+ char *inbuff = gpt_part_data->translated_name;
+ char *outbuff = (char *)&gpt_part_data->name;
+ size_t inbuffsize = strlen (inbuff) + 1;
+ size_t outbuffsize = 72;
+ if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
+ goto err;
+ iconv_close (conv);
+ return;
+ err:
+ ped_exception_throw (PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
+ iconv_close (conv);
}
static const char *
gpt_partition_get_name (const PedPartition *part)
{
GPTPartitionData *gpt_part_data = part->disk_specific;
- return gpt_part_data->name;
+ if (gpt_part_data->translated_name == NULL)
+ {
+ char buffer[200];
+ iconv_t conv = iconv_open (nl_langinfo (CODESET), "UTF-16");
+ if (conv == (iconv_t)-1)
+ goto err;
+ char *inbuff = (char *)&gpt_part_data->name;
+ char *outbuff = buffer;
+ size_t inbuffsize = 72;
+ size_t outbuffsize = sizeof(buffer);
+ if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
+ goto err;
+ iconv_close (conv);
+ *outbuff = 0;
+ gpt_part_data->translated_name = strdup (buffer);
+ return gpt_part_data->translated_name;
+ err:
+ ped_exception_throw (PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
+ iconv_close (conv);
+ }
+ return gpt_part_data->translated_name;
}
static int
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 16ec5d2..7a6fe8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,6 +27,7 @@ TESTS = \
t0212-gpt-many-partitions.sh \
t0220-gpt-msftres.sh \
t0250-gpt.sh \
+ t0251-gpt-unicode.sh \
t0280-gpt-corrupt.sh \
t0281-gpt-grow.sh \
t0282-gpt-move-backup.sh \
diff --git a/tests/t0251-gpt-unicode.sh b/tests/t0251-gpt-unicode.sh
new file mode 100644
index 0000000..580015e
--- /dev/null
+++ b/tests/t0251-gpt-unicode.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Test unicode partition names
+# Copyright (C) 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+dev=loop-file
+
+# create zeroed device
+truncate -s 10m $dev || fail=1
+
+# create gpt label with named partition
+parted -s $dev mklabel gpt mkpart primary ext2 1MiB 2MiB name 1 fooᴤ > empty 2>&1 || fail=1
+
+# ensure there was no output
+compare /dev/null empty || fail=1
+
+# check for expected output
+dd if=$dev bs=1 skip=$((512+$sector_size_+58)) count=10 2>/dev/null | hd
+ > out || fail=1
+cat <<EOF >> exp
+00000000 66 00 6f 00 6f 00 24 1d 00 00 |f.o.o.$...|
+0000000a
+EOF
+compare exp out || fail=1
+
+Exit $fail
--
1.8.3.2
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Sat, 21 Dec 2013 02:29:01 GMT)
Full text and
rfc822 format available.
Message #37 received at 15591 <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
So I added a test and just fired off the revised patch. Running the
test suite though, things go fubar. A bunch of tests fail with parted
crashing with a segfault. The first one is
t0205-gpt-list-clobbers-pmbr. The thing is, when I run the exact same
commands the test does by hand, they work just fine. Got any ideas?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBCgAGBQJStPyxAAoJEI5FoCIzSKrwV9AIAJOs/L5G8A5kQSfEhMekqjb2
XnRaqSFBY7uWLCFvbqozx6mFPfTIqkB0sP72XaqSWGTGSGYx0TXlkUIqt5Cc9Ltf
eZ9vjcuPkw+s6pnF4Z8wwc20dd5j53ZoMUI7db+h+lHss1PY+QcUmHVGfyNf4PaY
IQNu2Sk7raxhc12GwNpotESLXoAK8SULElNvWMU2El+24oUejKW6nfw2E/RQRmEf
BKA6ZxwlsMTw19zDGVYqcDbZdcatZPLpSu+/Svy7UzY0mBB1d/bIHk6sDoor+EIO
c++hVT6We1hfY8mOWwXDYAhJHVd3OsCZ9lMQGOzXTsJwV73PuJMCwZ7loVJTevk=
=Df7T
-----END PGP SIGNATURE-----
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Sat, 21 Dec 2013 18:32:01 GMT)
Full text and
rfc822 format available.
Message #40 received at 15591 <at> debbugs.gnu.org (full text, mbox):
On Fri, Dec 20, 2013 at 6:25 PM, Phillip Susi <psusi <at> ubuntu.com> wrote:
> gpt.c was simply truncating the UTF-16 characters stored
> in the partition name field to 8 bits. This corrupted non
> ascii characters which later resulted in parted crashing in
> strlist.c trying to convert the now invalid multi byte
> characters to wchar.
>
> gpt.c will now properly convert the UTF-16 to the current
> locale encoding.
Thanks for adding the test.
Please add something like this to NEWS, too:
parted no longer crashes when processing non-ASCII partition names
Please make the new t*.sh script executable.
> libparted/labels/gpt.c | 60 ++++++++++++++++++++++++++++++++++++++++------
> tests/Makefile.am | 1 +
> tests/t0251-gpt-unicode.sh | 40 +++++++++++++++++++++++++++++++
> diff --git a/tests/t0251-gpt-unicode.sh b/tests/t0251-gpt-unicode.sh
> new file mode 100644
...
> +dev=loop-file
> +
> +# create zeroed device
> +truncate -s 10m $dev || fail=1
> +
> +# create gpt label with named partition
> +parted -s $dev mklabel gpt mkpart primary ext2 1MiB 2MiB name 1 fooᴤ > empty 2>&1 || fail=1
Please keep the contents of this test source file ASCII, e.g.,
part_name=$(printf 'foo\341\264\244')
parted -s $dev mklabel gpt mkpart primary ext2 1MiB 2MiB name 1 fooᴤ
> empty 2>&1 || fail=1
> +# ensure there was no output
> +compare /dev/null empty || fail=1
> +
> +# check for expected output
> +dd if=$dev bs=1 skip=$((512+$sector_size_+58)) count=10 2>/dev/null | hd
> + > out || fail=1
We have never used "hd" so far in these tests.
Let's use "od" instead, e.g.,
$ printf 'foo\341\264\244\n'|od -An -tx1
66 6f 6f e1 b4 a4 0a
> +cat <<EOF >> exp
> +00000000 66 00 6f 00 6f 00 24 1d 00 00 |f.o.o.$...|
> +0000000a
> +EOF
Then the above four lines can become one line:
echo '...' > exp || framework_failure_
> +compare exp out || fail=1
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Sat, 21 Dec 2013 18:34:01 GMT)
Full text and
rfc822 format available.
Message #43 received at 15591 <at> debbugs.gnu.org (full text, mbox):
> Say, if you have some time for patch reviewing these days, think you
> could take a look at the online resize patch set? They have been in
> Debian and Ubuntu now for a bit and the last gparted livecd is using
> them, so it would be nice to finally get them applied upstream and a
> new release done.
I've put it on my list, but may not get to it before the new year.
If I don't reply by say Jan 10 or so, feel free to prod me :-)
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Sat, 21 Dec 2013 18:38:01 GMT)
Full text and
rfc822 format available.
Message #46 received at 15591 <at> debbugs.gnu.org (full text, mbox):
> So I added a test and just fired off the revised patch.
Thanks for doing that!
> Running the
> test suite though, things go fubar. A bunch of tests fail with parted
> crashing with a segfault. The first one is
> t0205-gpt-list-clobbers-pmbr. The thing is, when I run the exact same
> commands the test does by hand, they work just fine. Got any ideas?
Adjusting per my "use only ASCII in test script" may help.
If not, post a revised patch and I'll make time to investigate in the
next few days.
PS. please attach it or tell your editor not to split long lines ---
that mangles patches.
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Sat, 21 Dec 2013 23:09:02 GMT)
Full text and
rfc822 format available.
Message #49 received at 15591 <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
On 12/21/2013 01:37 PM, Jim Meyering wrote:
> Adjusting per my "use only ASCII in test script" may help. If not,
> post a revised patch and I'll make time to investigate in the next
> few days.
I didn't touch the other tests, so I don't see how having UTF-8
characters in a separate test could cause a failure ( in a test that
runs earlier no less ).
> PS. please attach it or tell your editor not to split long lines
> --- that mangles patches.
I don't follow. I send the patches with git-send-email.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBCgAGBQJSth+IAAoJEI5FoCIzSKrwkFIH/0zUiaNtD2W5zITWanbYac52
8vzSH1ADoz79Gig4nYu2CylY64np2AloGydtFENHsgvTWgw9O8OhabZ4jTxSJqgI
8dqdS/fdI7kcGHu+z0aqtFU/EIeF0uIk7MXHFKjIEwo2K0KamiKOugRm86JwHqz2
pEs87rvWhL+F7Llgl/6IGvoHrKCvTO/6Be7ObVovwUyW7sbXwTMl7xQBxkef/yGz
vxnJ/uhwPOQ2Xkj02/pI8x2RJf2iKYMGe/WL6C33vtK8eQwBUDXcT6go1XT5j8Dt
echPqklxI0IKAdCrofyqqS3ta/d3BjF8UaFZNESYxhOcN3ZkrlgkM2lHxJM6BEY=
=Pilf
-----END PGP SIGNATURE-----
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Sat, 21 Dec 2013 23:13:01 GMT)
Full text and
rfc822 format available.
Message #52 received at 15591 <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
On 12/21/2013 01:31 PM, Jim Meyering wrote:
> Please keep the contents of this test source file ASCII, e.g.,
Out of curiosity, why? Doesn't everyone handle UTF-8 these days?
> We have never used "hd" so far in these tests. Let's use "od"
> instead, e.g.,
>
> $ printf 'foo\341\264\244\n'|od -An -tx1 66 6f 6f e1 b4 a4 0a
I have used xxd before, how about that? I prefer the ASCII
interpretation column as it makes it more understandable.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBCgAGBQJStiBeAAoJEI5FoCIzSKrws2MH+gIgHe9Nq0t6WgcjkdgDHpw1
arYsUpcgZToZ5aJal8X4nNyMmEB59bAfAN2bvwVZ63yrptnRnmJQpnlzz6PjDrYL
y/mlVjo6/591kJufkmxSWvvuY1fGVhoB+1xIoL7H3roxkrzXzNgoMyhn2k1AEODw
gQuTGyXqCJzRiPTzUuXncXROBDFixUYE/Yk/k0OCg4P+f07N1TZ9imNXMcfMFErL
dUQlXiP/DE8ksRl3YWMmpRaj2mDcnYiZz3bbVoIrxg15tIFT8aCov+DDBEPc60Oi
6oF/uyUnkPfmfHda6SlNhQOHPY2jtA8EI5oii4GvnqWYyc6fQMk69TGwEnP0Ppk=
=Yl//
-----END PGP SIGNATURE-----
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Sun, 22 Dec 2013 01:41:02 GMT)
Full text and
rfc822 format available.
Message #55 received at 15591 <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
On 12/21/2013 01:31 PM, Jim Meyering wrote:
> Please make the new t*.sh script executable.
Why? I notice that half of the scripts are executable, but half are
not, and the ones that are can not be executed directly anyhow as it
seems they get paths wrong, and the make check rule doesn't care
whether they are executable or not.
On a related note, can you explain how the test suite works? I'm
trying to figure out why I can't just wrap the parted call in gdb to
debug the crash since it seems the scripts are run with stdin <
/dev/null, but I can not follow the Makefile for the life of me.
Looking at the main Makefile.am, it seems that the check rule only
runs check-other-sector_sizes, which calls make ss-{1024,2048,4096}.
Curiously, 512 byte sectors seem to be missing. The rules for the
ss-XXXX targets set PARTED_SECTOR_SIZE and call make check-recursive,
but there does not seem to be any such target.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBCgAGBQJStkMYAAoJEI5FoCIzSKrwHAUH/Av687crD6gCB/qE4aoOgfsy
aJa1jNWRnn6tl1an+j6sCtmYv5xtpZ0xyj7ysyqY5nUOJRcGpRCRyav/v3jkAbWh
Tmn90Ubwes5VAZ12wXE3Y/r4LRSo+hbobnadFp4TFrwGgQ+gkrrRM9IbGf12ePX0
CSNsM5dB6+9MrsIHq98z92d8tV0PEvuLSlT7/M/vQU8nhOUFe2Bdy9YvtmwQwPZa
zRIeYCiIB94yV1z6LgJjlXeQs8/HNITljHpc6vu3ZfGiBjCqFqADMpYAozJInRKd
/QKHJpBZD1XIeFxopRtHBkywwfJRD7W+3nyvf4XmohU3TNLmJoYVAbGo7nhzye8=
=bby8
-----END PGP SIGNATURE-----
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Mon, 23 Dec 2013 02:18:01 GMT)
Full text and
rfc822 format available.
Message #58 received at 15591 <at> debbugs.gnu.org (full text, mbox):
gpt.c was simply truncating the UTF-16 characters stored
in the partition name field to 8 bits. This corrupted non
ascii characters which later resulted in parted crashing in
strlist.c trying to convert the now invalid multi byte
characters to wchar.
gpt.c will now properly convert the UTF-16 to the current
locale encoding.
---
libparted/labels/gpt.c | 63 ++++++++++++++++++++++++++++++++++++++++------
tests/Makefile.am | 1 +
tests/t0251-gpt-unicode.sh | 38 ++++++++++++++++++++++++++++
3 files changed, 95 insertions(+), 7 deletions(-)
create mode 100755 tests/t0251-gpt-unicode.sh
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 66c96e6..dce89b1 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -39,6 +39,8 @@
#include <uuid/uuid.h>
#include <stdbool.h>
#include <errno.h>
+#include <iconv.h>
+#include <langinfo.h>
#include "xalloc.h"
#include "verify.h"
@@ -196,7 +198,7 @@ struct __attribute__ ((packed)) _GuidPartitionEntry_t
uint64_t StartingLBA;
uint64_t EndingLBA;
GuidPartitionEntryAttributes_t Attributes;
- efi_char16_t PartitionName[72 / sizeof (efi_char16_t)];
+ efi_char16_t PartitionName[36];
};
#define GPT_PMBR_LBA 0
@@ -281,7 +283,8 @@ typedef struct _GPTPartitionData
{
efi_guid_t type;
efi_guid_t uuid;
- char name[37];
+ efi_char16_t name[37];
+ char *translated_name;
int lvm;
int raid;
int boot;
@@ -797,10 +800,11 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
gpt_part_data = part->disk_specific;
gpt_part_data->type = pte->PartitionTypeGuid;
gpt_part_data->uuid = pte->UniquePartitionGuid;
- for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
+ for (i = 0; i < 36; i++)
gpt_part_data->name[i] =
(efi_char16_t) PED_LE16_TO_CPU ((uint16_t) pte->PartitionName[i]);
gpt_part_data->name[i] = 0;
+ gpt_part_data->translated_name = 0;
gpt_part_data->lvm = gpt_part_data->raid
= gpt_part_data->boot = gpt_part_data->hp_service
@@ -1210,7 +1214,7 @@ _partition_generate_part_entry (PedPartition *part, GuidPartitionEntry_t *pte)
if (gpt_part_data->legacy_boot)
pte->Attributes.LegacyBIOSBootable = 1;
- for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
+ for (i = 0; i < 36; i++)
pte->PartitionName[i]
= (efi_char16_t) PED_CPU_TO_LE16 ((uint16_t) gpt_part_data->name[i]);
}
@@ -1353,6 +1357,7 @@ gpt_partition_new (const PedDisk *disk,
gpt_part_data->atvrecv = 0;
gpt_part_data->legacy_boot = 0;
gpt_part_data->prep = 0;
+ gpt_part_data->translated_name = 0;
uuid_generate ((unsigned char *) &gpt_part_data->uuid);
swap_uuid_and_efi_guid ((unsigned char *) (&gpt_part_data->uuid));
memset (gpt_part_data->name, 0, sizeof gpt_part_data->name);
@@ -1386,6 +1391,9 @@ gpt_partition_duplicate (const PedPartition *part)
goto error_free_part;
*result_data = *part_data;
+ if (part_data->translated_name)
+ result_data->translated_name = xstrdup (part_data->translated_name);
+ else part_data->translated_name = 0;
return result;
error_free_part:
@@ -1400,6 +1408,8 @@ gpt_partition_destroy (PedPartition *part)
if (part->type == 0)
{
PED_ASSERT (part->disk_specific != NULL);
+ GPTPartitionData *gpt_part_data = part->disk_specific;
+ free (gpt_part_data->translated_name);
free (part->disk_specific);
}
@@ -1820,15 +1830,54 @@ gpt_partition_set_name (PedPartition *part, const char *name)
{
GPTPartitionData *gpt_part_data = part->disk_specific;
- strncpy (gpt_part_data->name, name, 36);
- gpt_part_data->name[36] = 0;
+ free(gpt_part_data->translated_name);
+ gpt_part_data->translated_name = xstrdup(name);
+ iconv_t conv = iconv_open ("UTF-16", nl_langinfo (CODESET));
+ if (conv == (iconv_t)-1)
+ goto err;
+ char *inbuff = gpt_part_data->translated_name;
+ char *outbuff = (char *)&gpt_part_data->name;
+ size_t inbuffsize = strlen (inbuff) + 1;
+ size_t outbuffsize = 72;
+ if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
+ goto err;
+ iconv_close (conv);
+ return;
+ err:
+ ped_exception_throw (PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
+ iconv_close (conv);
}
static const char *
gpt_partition_get_name (const PedPartition *part)
{
GPTPartitionData *gpt_part_data = part->disk_specific;
- return gpt_part_data->name;
+ if (gpt_part_data->translated_name == NULL)
+ {
+ char buffer[200];
+ iconv_t conv = iconv_open (nl_langinfo (CODESET), "UTF-16");
+ if (conv == (iconv_t)-1)
+ goto err;
+ char *inbuff = (char *)&gpt_part_data->name;
+ char *outbuff = buffer;
+ size_t inbuffsize = 72;
+ size_t outbuffsize = sizeof(buffer);
+ if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
+ goto err;
+ iconv_close (conv);
+ *outbuff = 0;
+ gpt_part_data->translated_name = xstrdup (buffer);
+ return gpt_part_data->translated_name;
+ err:
+ ped_exception_throw (PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
+ iconv_close (conv);
+ return "";
+ }
+ return gpt_part_data->translated_name;
}
static int
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 16ec5d2..7a6fe8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,6 +27,7 @@ TESTS = \
t0212-gpt-many-partitions.sh \
t0220-gpt-msftres.sh \
t0250-gpt.sh \
+ t0251-gpt-unicode.sh \
t0280-gpt-corrupt.sh \
t0281-gpt-grow.sh \
t0282-gpt-move-backup.sh \
diff --git a/tests/t0251-gpt-unicode.sh b/tests/t0251-gpt-unicode.sh
new file mode 100755
index 0000000..a2b4b04
--- /dev/null
+++ b/tests/t0251-gpt-unicode.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Test unicode partition names
+# Copyright (C) 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+dev=loop-file
+
+# create zeroed device
+truncate -s 10m $dev || fail=1
+
+export LC_ALL=en_US.UTF-8
+# create gpt label with named partition
+part_name=$(printf 'foo\341\264\244')
+parted -s $dev mklabel gpt mkpart primary ext2 1MiB 2MiB name 1 $part_name > empty 2>&1 || fail=1
+
+# ensure there was no output
+compare /dev/null empty || fail=1
+
+# check for expected output
+dd if=$dev bs=1 skip=$(($sector_size_+$sector_size_+58)) count=10 2>/dev/null | od -An -tx1 > out || fail=1
+echo \ 66 00 6f 00 6f 00 24 1d 00 00 >> exp
+compare exp out || fail=1
+
+Exit $fail
--
1.8.3.2
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Mon, 23 Dec 2013 02:46:01 GMT)
Full text and
rfc822 format available.
Message #61 received at 15591 <at> debbugs.gnu.org (full text, mbox):
On Sun, Dec 22, 2013 at 6:17 PM, Phillip Susi <psusi <at> ubuntu.com> wrote:
> +# check for expected output
> +dd if=$dev bs=1 skip=$(($sector_size_+$sector_size_+58)) count=10 2>/dev/null | od -An -tx1 > out || fail=1
> +echo \ 66 00 6f 00 6f 00 24 1d 00 00 >> exp
Thank you. That looks correct and is now more portable.
To avoid minor "reviewer surprise", I suggest to drop the use of
backslash-space and instead use single quotes around the
entire line, and use ">" rather than ">>", e.g.,
echo ' 66 00 6f 00 6f 00 24 1d 00 00' > exp
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Mon, 23 Dec 2013 02:48:02 GMT)
Full text and
rfc822 format available.
Message #64 received at 15591 <at> debbugs.gnu.org (full text, mbox):
Oh, and please add an item to NEWS, e.g.,
the sentence I suggested a day or two ago.
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Mon, 23 Dec 2013 03:14:01 GMT)
Full text and
rfc822 format available.
Message #67 received at 15591 <at> debbugs.gnu.org (full text, mbox):
gpt.c was simply truncating the UTF-16 characters stored
in the partition name field to 8 bits. This corrupted non
ascii characters which later resulted in parted crashing in
strlist.c trying to convert the now invalid multi byte
characters to wchar.
gpt.c will now properly convert the UTF-16 to the current
locale encoding.
---
NEWS | 1 +
libparted/labels/gpt.c | 63 ++++++++++++++++++++++++++++++++++++++++------
tests/Makefile.am | 1 +
tests/t0251-gpt-unicode.sh | 38 ++++++++++++++++++++++++++++
4 files changed, 96 insertions(+), 7 deletions(-)
create mode 100755 tests/t0251-gpt-unicode.sh
diff --git a/NEWS b/NEWS
index 9d0d931..935fa33 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ GNU parted NEWS -*- outline -*-
boot partition type.
** Bug Fixes
+ Fix gpt to correctly handle non ASCII charcters in partition names
If a drive was 100 times an even multiple of two, sizes specified as
a percentage would trigger the exact placement rule and refuse to round
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 66c96e6..dce89b1 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -39,6 +39,8 @@
#include <uuid/uuid.h>
#include <stdbool.h>
#include <errno.h>
+#include <iconv.h>
+#include <langinfo.h>
#include "xalloc.h"
#include "verify.h"
@@ -196,7 +198,7 @@ struct __attribute__ ((packed)) _GuidPartitionEntry_t
uint64_t StartingLBA;
uint64_t EndingLBA;
GuidPartitionEntryAttributes_t Attributes;
- efi_char16_t PartitionName[72 / sizeof (efi_char16_t)];
+ efi_char16_t PartitionName[36];
};
#define GPT_PMBR_LBA 0
@@ -281,7 +283,8 @@ typedef struct _GPTPartitionData
{
efi_guid_t type;
efi_guid_t uuid;
- char name[37];
+ efi_char16_t name[37];
+ char *translated_name;
int lvm;
int raid;
int boot;
@@ -797,10 +800,11 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
gpt_part_data = part->disk_specific;
gpt_part_data->type = pte->PartitionTypeGuid;
gpt_part_data->uuid = pte->UniquePartitionGuid;
- for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
+ for (i = 0; i < 36; i++)
gpt_part_data->name[i] =
(efi_char16_t) PED_LE16_TO_CPU ((uint16_t) pte->PartitionName[i]);
gpt_part_data->name[i] = 0;
+ gpt_part_data->translated_name = 0;
gpt_part_data->lvm = gpt_part_data->raid
= gpt_part_data->boot = gpt_part_data->hp_service
@@ -1210,7 +1214,7 @@ _partition_generate_part_entry (PedPartition *part, GuidPartitionEntry_t *pte)
if (gpt_part_data->legacy_boot)
pte->Attributes.LegacyBIOSBootable = 1;
- for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
+ for (i = 0; i < 36; i++)
pte->PartitionName[i]
= (efi_char16_t) PED_CPU_TO_LE16 ((uint16_t) gpt_part_data->name[i]);
}
@@ -1353,6 +1357,7 @@ gpt_partition_new (const PedDisk *disk,
gpt_part_data->atvrecv = 0;
gpt_part_data->legacy_boot = 0;
gpt_part_data->prep = 0;
+ gpt_part_data->translated_name = 0;
uuid_generate ((unsigned char *) &gpt_part_data->uuid);
swap_uuid_and_efi_guid ((unsigned char *) (&gpt_part_data->uuid));
memset (gpt_part_data->name, 0, sizeof gpt_part_data->name);
@@ -1386,6 +1391,9 @@ gpt_partition_duplicate (const PedPartition *part)
goto error_free_part;
*result_data = *part_data;
+ if (part_data->translated_name)
+ result_data->translated_name = xstrdup (part_data->translated_name);
+ else part_data->translated_name = 0;
return result;
error_free_part:
@@ -1400,6 +1408,8 @@ gpt_partition_destroy (PedPartition *part)
if (part->type == 0)
{
PED_ASSERT (part->disk_specific != NULL);
+ GPTPartitionData *gpt_part_data = part->disk_specific;
+ free (gpt_part_data->translated_name);
free (part->disk_specific);
}
@@ -1820,15 +1830,54 @@ gpt_partition_set_name (PedPartition *part, const char *name)
{
GPTPartitionData *gpt_part_data = part->disk_specific;
- strncpy (gpt_part_data->name, name, 36);
- gpt_part_data->name[36] = 0;
+ free(gpt_part_data->translated_name);
+ gpt_part_data->translated_name = xstrdup(name);
+ iconv_t conv = iconv_open ("UTF-16", nl_langinfo (CODESET));
+ if (conv == (iconv_t)-1)
+ goto err;
+ char *inbuff = gpt_part_data->translated_name;
+ char *outbuff = (char *)&gpt_part_data->name;
+ size_t inbuffsize = strlen (inbuff) + 1;
+ size_t outbuffsize = 72;
+ if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
+ goto err;
+ iconv_close (conv);
+ return;
+ err:
+ ped_exception_throw (PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
+ iconv_close (conv);
}
static const char *
gpt_partition_get_name (const PedPartition *part)
{
GPTPartitionData *gpt_part_data = part->disk_specific;
- return gpt_part_data->name;
+ if (gpt_part_data->translated_name == NULL)
+ {
+ char buffer[200];
+ iconv_t conv = iconv_open (nl_langinfo (CODESET), "UTF-16");
+ if (conv == (iconv_t)-1)
+ goto err;
+ char *inbuff = (char *)&gpt_part_data->name;
+ char *outbuff = buffer;
+ size_t inbuffsize = 72;
+ size_t outbuffsize = sizeof(buffer);
+ if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
+ goto err;
+ iconv_close (conv);
+ *outbuff = 0;
+ gpt_part_data->translated_name = xstrdup (buffer);
+ return gpt_part_data->translated_name;
+ err:
+ ped_exception_throw (PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
+ iconv_close (conv);
+ return "";
+ }
+ return gpt_part_data->translated_name;
}
static int
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 16ec5d2..7a6fe8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,6 +27,7 @@ TESTS = \
t0212-gpt-many-partitions.sh \
t0220-gpt-msftres.sh \
t0250-gpt.sh \
+ t0251-gpt-unicode.sh \
t0280-gpt-corrupt.sh \
t0281-gpt-grow.sh \
t0282-gpt-move-backup.sh \
diff --git a/tests/t0251-gpt-unicode.sh b/tests/t0251-gpt-unicode.sh
new file mode 100755
index 0000000..36a4c26
--- /dev/null
+++ b/tests/t0251-gpt-unicode.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Test unicode partition names
+# Copyright (C) 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+dev=loop-file
+
+# create zeroed device
+truncate -s 10m $dev || fail=1
+
+export LC_ALL=en_US.UTF-8
+# create gpt label with named partition
+part_name=$(printf 'foo\341\264\244')
+parted -s $dev mklabel gpt mkpart primary ext2 1MiB 2MiB name 1 $part_name > empty 2>&1 || fail=1
+
+# ensure there was no output
+compare /dev/null empty || fail=1
+
+# check for expected output
+dd if=$dev bs=1 skip=$(($sector_size_+$sector_size_+58)) count=10 2>/dev/null | od -An -tx1 > out || fail=1
+echo ' 66 00 6f 00 6f 00 24 1d 00 00' >> exp
+compare exp out || fail=1
+
+Exit $fail
--
1.8.3.2
Reply sent
to
Jim Meyering <jim <at> meyering.net>
:
You have taken responsibility.
(Mon, 23 Dec 2013 03:46:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Phillip Susi <psusi <at> ubuntu.com>
:
bug acknowledged by developer.
(Mon, 23 Dec 2013 03:46:02 GMT)
Full text and
rfc822 format available.
Message #72 received at 15591-done <at> debbugs.gnu.org (full text, mbox):
Perfect. Thanks! Marking this "done" in the bug-tracker.
Reply sent
to
Jim Meyering <jim <at> meyering.net>
:
You have taken responsibility.
(Mon, 23 Dec 2013 03:46:03 GMT)
Full text and
rfc822 format available.
Notification sent
to
Rod Smith <rodsmith <at> rodsbooks.com>
:
bug acknowledged by developer.
(Mon, 23 Dec 2013 03:46:03 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-parted <at> gnu.org
:
bug#15591
; Package
parted
.
(Mon, 23 Dec 2013 15:22:01 GMT)
Full text and
rfc822 format available.
Message #80 received at 15591 <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/22/2013 10:45 PM, Jim Meyering wrote:
> Perfect. Thanks! Marking this "done" in the bug-tracker.
Great, pushed.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJSuFUGAAoJEI5FoCIzSKrwE9MH/RKiruOVv5gIDCsOTG9/Cq64
EdB93f/q6mzBZnNwWEeZk9xoNpu4ueUHqOWU89zdsgVd0Dk4S0CyQoh0jAe9p1z1
CF1zdLldOxFSYxj3iQsPg4Wj2B/lAIgPV08b8XY+/De/KrOh8br5lt0NUSVzKuyJ
ZTBVYDNnfItW04mva/cXFwztmaLzQK3DIJ/tqszz/4GNongOh5wBtI9B3lzYbOVO
KdDksESg6F5izaCw1+nBD70xmDO6qS9VUX0qFlVKdiqQf+wohYKmkakM3DMYIEQ7
hMxMZYaWIQnoheWjyTWGYkzluNwyHqyQjjBamBPRkP5IB2juWHdP+dg2ckZZ9U8=
=KyKE
-----END PGP SIGNATURE-----
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 21 Jan 2014 12:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 11 years and 153 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.