Skip to content

Commit

Permalink
Strict string check
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbadfca11 committed May 12, 2019
1 parent fb5c15e commit 8466ee9
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions fat32format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ int format_volume(_In_z_ LPCSTR vol, _In_ const format_params* params)

// Now we're commited - print some info first
printf("Size : %gGB %lu sectors\n", piDrive.PartitionLength.QuadPart / (1024.f * 1024.f * 1024.f), TotalSectors);
printf("%lu Bytes Per Sector, Cluster size %lu bytes\n", BytesPerSect, SectorsPerCluster*BytesPerSect);
printf("%lu Bytes Per Sector, Cluster size %lu bytes\n", BytesPerSect, SectorsPerCluster * BytesPerSect);
printf("Volume ID is %04lX:%04lX\n", pFAT32BootSect->dBS_VolID >> 16, pFAT32BootSect->dBS_VolID & 0xffff);
printf("%u Reserved Sectors, %lu Sectors per FAT, %u fats\n", ReservedSectCount, FatSize, NumFATs);

Expand Down Expand Up @@ -740,14 +740,29 @@ int main(int argc, char* argv[])
usage();
}

if (isalpha(volume_argv[0]) || strncmp(volume_argv, R"(\\.\)", 4) == 0)
if (strncmp(volume_argv, R"(\\?\Volume{)", 11) == 0)
{
char volume_guid[50];
strcpy_s(volume_guid, volume_argv);
if (size_t pos = strlen(volume_guid) - 1; volume_guid[pos] == '\\')
{
volume_guid[pos] = '\0';
}
format_volume(volume_guid, &p);
strcat_s(volume_guid, "\\");
if (!SetVolumeLabelA(volume_guid, p.volume_label))
{
die("Failed to set volume label");
}
}
else
{
char volume[8] = R"(\\.\?:)";
if (strcmp(&volume_argv[1], ":") == 0)
if (strlen(volume_argv) == 2 && isalpha(volume_argv[0]) && volume_argv[1] == ':')
{
volume[4] = volume_argv[0];
}
else if (strlen(volume_argv) == 6 && isalpha(volume_argv[4]) && volume_argv[5] == ':')
else if (strlen(volume_argv) == 6 && strncmp(volume_argv, R"(\\.\)", 4) == 0 && isalpha(volume_argv[4]) && volume_argv[5] == ':')
{
volume[4] = volume_argv[4];
}
Expand All @@ -762,23 +777,4 @@ int main(int argc, char* argv[])
die("Failed to set volume label");
}
}
else if (strncmp(volume_argv, R"(\\?\Volume{)", 11) == 0)
{
char volume_guid[50];
strcpy_s(volume_guid, volume_argv);
if (size_t pos = strlen(volume_guid) - 1; volume_guid[pos] == '\\')
{
volume_guid[pos] = '\0';
}
format_volume(volume_guid, &p);
strcat_s(volume_guid, "\\");
if (!SetVolumeLabelA(volume_guid, p.volume_label))
{
die("Failed to set volume label");
}
}
else
{
usage();
}
}

0 comments on commit 8466ee9

Please sign in to comment.