Skip to content

Commit c12ea5e

Browse files
committed
bug: Fixing memory allocation error in openSeaChest_Raw
Fixing a bug where memory will not be allocated properly for issuing a raw command. Part of the issue is that the device's block size is not populated and part of the issue is unclear command line options and option parsing. I resolved the option parsing and help text for the options in this commit. Signed-off-by: Tyler Erickson <[email protected]>
1 parent 7ff73c4 commit c12ea5e

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/openseachest_util_options.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5345,7 +5345,8 @@ void print_Raw_Data_Length_Help(bool shortHelp)
53455345
printf("\t\tThe following post fixes are allowed for\n");
53465346
printf("\t\tspecifying a transfer length:\n");
53475347
printf("\t\t\tBLOCKS - used to specify a transfer length\n");
5348-
printf("\t\t\t\tin device logical blocks. (Preferred)\n");
5348+
printf("\t\t\t\tin device logical blocks.\n");
5349+
printf("\t\t\tB - length in bytes (val * 1) (default if no unit given)\n");
53495350
printf("\t\t\tKB - length in kilobytes (val * 1000)\n");
53505351
printf("\t\t\tKiB - length in kibibytes (val * 1024)\n");
53515352
printf("\t\t\tMB - length in megabytes (val * 1000000)\n");
@@ -5416,7 +5417,8 @@ void print_Raw_Input_File_Offset_Help(bool shortHelp)
54165417
printf("\t\tThe following post fixes are allowed for\n");
54175418
printf("\t\tspecifying a transfer length:\n");
54185419
printf("\t\t\tBLOCKS - used to specify an offset length\n");
5419-
printf("\t\t\t\tin device logical blocks. (Preferred)\n");
5420+
printf("\t\t\t\tin device logical blocks.\n");
5421+
printf("\t\t\tB - length in bytes (val * 1) (Default if no unit given)\n");
54205422
printf("\t\t\tKB - length in kilobytes (val * 1000)\n");
54215423
printf("\t\t\tKiB - length in kibibytes (val * 1024)\n");
54225424
printf("\t\t\tMB - length in megabytes (val * 1000000)\n");

utils/C/openSeaChest/openSeaChest_Raw.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Global Variables //
3030
////////////////////////
3131
const char* util_name = "openSeaChest_Raw";
32-
const char* buildVersion = "0.9.0";
32+
const char* buildVersion = "0.9.1";
3333

3434
////////////////////////////
3535
// functions to declare //
@@ -550,14 +550,14 @@ int main(int argc, char* argv[])
550550
uint32_t multiplier = UINT32_C(1);
551551
if (unit)
552552
{
553-
if (strcmp(unit, "") == 0)
553+
if (strcmp(unit, "BLOCKS") == 0 || strcmp(unit, "SECTORS") == 0)
554554
{
555+
// they specified blocks. For log transfers this means a number of 512B sectors
555556
RAW_DATA_LEN_ADJUST_BY_BLOCKS_FLAG = true;
556557
}
557-
else if (strcmp(unit, "BLOCKS") == 0 || strcmp(unit, "SECTORS") == 0)
558+
else if (strcmp(unit, "B") == 0 || strcmp(unit, "") == 0)
558559
{
559-
// they specified blocks. For log transfers this means a number of 512B sectors
560-
multiplier = LEGACY_DRIVE_SEC_SIZE;
560+
multiplier = UINT32_C(1);
561561
}
562562
else if (strcmp(unit, "KB") == 0)
563563
{
@@ -590,6 +590,7 @@ int main(int argc, char* argv[])
590590
}
591591
}
592592
RAW_DATA_LEN_FLAG *= multiplier;
593+
printf("Raw data len = %" PRIu32 "\n", RAW_DATA_LEN_FLAG);
593594
}
594595
else
595596
{
@@ -1316,7 +1317,7 @@ int main(int argc, char* argv[])
13161317
dataBuffer = M_REINTERPRET_CAST(
13171318
uint8_t*, safe_calloc_aligned(allocatedDataLength, sizeof(uint8_t),
13181319
deviceList[deviceIter].os_info.minimumAlignment));
1319-
if (!dataBuffer)
1320+
if (dataBuffer == M_NULLPTR)
13201321
{
13211322
if (VERBOSITY_QUIET < toolVerbosity)
13221323
{
@@ -1620,9 +1621,7 @@ int main(int argc, char* argv[])
16201621
exitCode = UTIL_EXIT_ERROR_IN_COMMAND_LINE;
16211622
}
16221623
}
1623-
1624-
// perform some sort of validation to see that we have some command to send...then build it and send it.
1625-
if (RAW_TFR_SIZE_FLAG != 0 && RAW_TFR_PROTOCOL != -1 && RAW_TFR_XFER_LENGTH_LOCATION != -1 &&
1624+
else if (RAW_TFR_SIZE_FLAG != 0 && RAW_TFR_PROTOCOL != -1 && RAW_TFR_XFER_LENGTH_LOCATION != -1 &&
16261625
RAW_TFR_BYTE_BLOCK != -1)
16271626
{
16281627
ataPassthroughCommand passthroughCommand;

0 commit comments

Comments
 (0)