@@ -1723,14 +1723,15 @@ static gboolean set_part_type (struct fdisk_context *cxt, gint part_num, const g
17231723 struct fdisk_partition * pa = NULL ;
17241724 struct fdisk_parttype * ptype = NULL ;
17251725 const gchar * label_name = NULL ;
1726+ gchar * endptr = NULL ;
17261727 gint status = 0 ;
17271728 gint part_id_int = 0 ;
17281729
17291730 /* check if part type/id is valid for MBR */
17301731 if (table_type == BD_PART_TABLE_MSDOS ) {
1731- part_id_int = g_ascii_strtoull (type_str , NULL , 0 );
1732+ part_id_int = g_ascii_strtoull (type_str , & endptr , 0 );
17321733
1733- if (part_id_int == 0 ) {
1734+ if (part_id_int == 0 || endptr == NULL || * endptr != '\0' ) {
17341735 g_set_error (error , BD_PART_ERROR , BD_PART_ERROR_INVAL ,
17351736 "Invalid partition id given: '%s'." , type_str );
17361737 return FALSE;
@@ -1772,6 +1773,18 @@ static gboolean set_part_type (struct fdisk_context *cxt, gint part_num, const g
17721773 return FALSE;
17731774 }
17741775
1776+ if (table_type == BD_PART_TABLE_MSDOS ) {
1777+ /* for GPT types unknown by libfdisk might still be valid */
1778+ status = fdisk_parttype_is_unknown (ptype );
1779+ if (status != 0 ) {
1780+ g_set_error (error , BD_PART_ERROR , BD_PART_ERROR_INVAL ,
1781+ "Invalid partition type given: '%s'." , type_str );
1782+ fdisk_unref_parttype (ptype );
1783+ fdisk_unref_partition (pa );
1784+ return FALSE;
1785+ }
1786+ }
1787+
17751788 status = fdisk_set_partition_type (cxt , part_num , ptype );
17761789 if (status != 0 ) {
17771790 g_set_error (error , BD_PART_ERROR , BD_PART_ERROR_FAIL ,
0 commit comments