Compare commits

..

2 Commits

32
otp.c
View File

@@ -132,12 +132,16 @@ int main(int argc, char* argv[]) {
} }
int interactive_mode(void) { int interactive_mode(void) {
// printf("\n\n\n\n=== OTP Cipher %s ===\n\n", get_version()); char input[10];
while (1) { while (1) {
show_main_menu(); show_main_menu();
char input[10];
if (fgets(input, sizeof(input), stdin)) { if (!fgets(input, sizeof(input), stdin)) {
printf("Goodbye!\n");
break;
}
char choice = toupper(input[0]); char choice = toupper(input[0]);
switch (choice) { switch (choice) {
@@ -154,19 +158,15 @@ int interactive_mode(void) {
handle_pads_menu(); handle_pads_menu();
break; break;
case 'X': case 'X':
case 'Q':
printf("Goodbye!\n"); printf("Goodbye!\n");
return 0; return 0;
default: default:
printf("Invalid option. Please select T, F, D, P, or X.\n"); printf("Invalid choice. Please try again.\n");
continue; break;
} }
} else {
printf("Error reading input. Please try again.\n");
continue;
}
printf("\n");
} }
return 0;
} }
int command_line_mode(int argc, char* argv[]) { int command_line_mode(int argc, char* argv[]) {
@@ -767,7 +767,7 @@ int list_available_pads(void) {
chksum[64] = '\0'; chksum[64] = '\0';
// Get pad file size // Get pad file size
char full_path[300]; // Increased buffer size to accommodate longer paths char full_path[1024]; // Increased buffer size to accommodate longer paths
snprintf(full_path, sizeof(full_path), "%s/%s", current_pads_dir, entry->d_name); snprintf(full_path, sizeof(full_path), "%s/%s", current_pads_dir, entry->d_name);
struct stat st; struct stat st;
if (stat(full_path, &st) == 0) { if (stat(full_path, &st) == 0) {
@@ -2095,7 +2095,7 @@ int decrypt_ascii_file(const char* input_file, const char* output_file) {
} }
int read_state_offset(const char* pad_chksum, uint64_t* offset) { int read_state_offset(const char* pad_chksum, uint64_t* offset) {
char state_filename[MAX_HASH_LENGTH + 20]; char state_filename[1024];
snprintf(state_filename, sizeof(state_filename), "%s/%s.state", current_pads_dir, pad_chksum); snprintf(state_filename, sizeof(state_filename), "%s/%s.state", current_pads_dir, pad_chksum);
FILE* state_file = fopen(state_filename, "rb"); FILE* state_file = fopen(state_filename, "rb");
@@ -2115,7 +2115,7 @@ int read_state_offset(const char* pad_chksum, uint64_t* offset) {
} }
int write_state_offset(const char* pad_chksum, uint64_t offset) { int write_state_offset(const char* pad_chksum, uint64_t offset) {
char state_filename[MAX_HASH_LENGTH + 20]; char state_filename[1024];
snprintf(state_filename, sizeof(state_filename), "%s/%s.state", current_pads_dir, pad_chksum); snprintf(state_filename, sizeof(state_filename), "%s/%s.state", current_pads_dir, pad_chksum);
FILE* state_file = fopen(state_filename, "wb"); FILE* state_file = fopen(state_filename, "wb");
@@ -2289,8 +2289,8 @@ void get_default_file_path(const char* filename, char* result_path, size_t resul
} }
void get_pad_path(const char* chksum, char* pad_path, char* state_path) { void get_pad_path(const char* chksum, char* pad_path, char* state_path) {
snprintf(pad_path, MAX_HASH_LENGTH + 20, "%s/%s.pad", current_pads_dir, chksum); snprintf(pad_path, 1024, "%s/%s.pad", current_pads_dir, chksum);
snprintf(state_path, MAX_HASH_LENGTH + 20, "%s/%s.state", current_pads_dir, chksum); snprintf(state_path, 1024, "%s/%s.state", current_pads_dir, chksum);
} }
// OTP thumb drive detection function implementation // OTP thumb drive detection function implementation