key参数长度导致bug修复

This commit is contained in:
aixiao 2023-01-30 14:35:44 +08:00
parent 2a3d35e328
commit 15aba655f0

13
sha.c
View File

@ -753,7 +753,10 @@ void usage(void)
int main(int argc, char *argv[])
{
static uint8_t key[16] = "aixiao.me";
int key_l = 0;
char sh_file[1024];
int opt;
char optstrs[] = ":k:f:h?";
while (-1 != (opt = getopt(argc, argv, optstrs))) {
@ -764,7 +767,6 @@ int main(int argc, char *argv[])
case 'f':
strcpy((char *)sh_file, optarg);
break;
case ':':
//printf("\nMissing argument after: -%c\n", optopt);
usage();
@ -777,11 +779,16 @@ int main(int argc, char *argv[])
}
}
if (strlen((char *)key) < 8) {
printf("Key must be at least 8 digits!\n");
key_l = strlen((char *)key);
//printf("%d\n", key_l);
if (key_l < 8 || key_l > 15) {
printf("The key must be 8-15 digits!\n");
exit(1);
}
open_file(sh_file);
struct AES_ctx ctx;