Skip to content

Commit

Permalink
Remove sha256 --skip-end feature as discussed during PR review process
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Sep 29, 2024
1 parent cdba28e commit 1b013d2
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,21 +532,20 @@ void parse_args(int argc, char* argv[])
}

// sha256sum mode
if((argc == 3 || (argc == 4 && strcmp(argv[2], "--skip-end"))) && strcmp(argv[1], "sha256sum") == 0)
if(argc == 3 && strcmp(argv[1], "sha256sum") == 0)
{
const bool skip_end = argc == 4;
// Enable stdout printing
cli_mode = true;
uint8_t checksum[SHA256_DIGEST_SIZE];
if(!sha256sum(argv[skip_end ? 3 : 2], checksum, skip_end))
if(!sha256sum(argv[2], checksum, false))

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This argument to a file access function is derived from
user input (a command-line argument)
and then passed to sha256sum(path), which calls FTLfopen(pathname), which calls fopen(__filename).
exit(EXIT_FAILURE);

// Convert checksum to hex string
char hex[SHA256_DIGEST_SIZE*2+1];
sha256_raw_to_hex(checksum, hex);

// Print result
printf("%s %s\n", hex, argv[skip_end ? 3 : 2]);
printf("%s %s\n", hex, argv[2]);
exit(EXIT_SUCCESS);
}

Expand Down Expand Up @@ -1097,12 +1096,11 @@ void parse_args(int argc, char* argv[])
printf(" Usage: %spihole-FTL ntp %s[server]%s %s[--update]%s\n\n", green, cyan, normal, purple, normal);

printf("%sSHA256 checksum tools:%s\n", yellow, normal);
printf(" Calculates the SHA256 checksum of a file.\n\n");
printf(" Calculates the SHA256 checksum of a file. The checksum is\n");
printf(" computed as described in FIPS-180-2 and uses straeaming\n");
printf(" to allow processing arbitrary large files with a small\n");
printf(" memory footprint.\n\n");
printf(" Usage: %spihole-FTL sha256sum %sfile%s\n\n", green, cyan, normal);
printf(" The special flag %s--skip-end%s can be used to skip the last 32\n", purple, normal);
printf(" bytes of the file. This is useful for files which have their\n");
printf(" checksum appended at the end of the file, e.g., pihole-FTL:\n\n");
printf(" %spihole-FTL sha256sum %s--skip_end %sfile%s\n\n", green, purple, cyan, normal);

printf("%sOther:%s\n", yellow, normal);
printf("\t%sverify%s Verify the integrity of the FTL binary\n", green, normal);
Expand Down

0 comments on commit 1b013d2

Please sign in to comment.