Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a9974c7e87 | |||
| 592d54728b |
@@ -1,7 +1,29 @@
|
|||||||
|
|
||||||
When building, use build.sh, not make.
|
When building, use build.sh, not make.
|
||||||
|
|
||||||
Use it as follows: build.sh -m "useful comment on changes being made"
|
Use it as follows: build.sh -m "useful comment on changes being made"
|
||||||
|
|
||||||
When making TUI menus, try to use the first leter of the command and the key to press to execute that command. For example, if the command is "Open file" try to use a keypress of "o" upper or lower case to signal to open the file. Use this instead of number keyed menus when possible. In the command, the letter should be underlined that signifies the command.
|
When making TUI menus, try to use the first leter of the command and the key to press to execute that command. For example, if the command is "Open file" try to use a keypress of "o" upper or lower case to signal to open the file. Use this instead of number keyed menus when possible. In the command, the letter should be underlined that signifies the command.
|
||||||
|
|
||||||
|
## Buffer Size Guidelines
|
||||||
|
|
||||||
|
### Path Handling
|
||||||
|
- Always use buffers of size 1024 or PATH_MAX (4096) for file paths
|
||||||
|
- When concatenating paths with snprintf, ensure buffer is at least 2x the expected maximum input
|
||||||
|
- Use safer path construction patterns that check lengths before concatenation
|
||||||
|
|
||||||
|
### String Formatting Safety
|
||||||
|
- Before using snprintf with dynamic strings, validate that buffer size >= sum of all input string lengths + format characters + 1
|
||||||
|
- Use strnlen() to check actual string lengths before formatting
|
||||||
|
- Consider using asprintf() for dynamic allocation when exact size is unknown
|
||||||
|
- Add length validation before snprintf calls
|
||||||
|
|
||||||
|
### Compiler Warning Prevention
|
||||||
|
- Always size string buffers generously (minimum 1024 for paths, 512 for general strings)
|
||||||
|
- Use buffer size calculations: `size >= strlen(str1) + strlen(str2) + format_overhead + 1`
|
||||||
|
- Add runtime length checks before snprintf operations
|
||||||
|
- Consider using safer alternatives like strlcpy/strlcat if available
|
||||||
|
|
||||||
|
### Code Patterns to Avoid
|
||||||
|
- Fixed-size buffers (512 bytes) for path operations where inputs could be 255+ bytes each
|
||||||
|
- Concatenating unchecked strings with snprintf
|
||||||
|
- Assuming maximum path component sizes without validation
|
||||||
|
|||||||
16
otp.c
16
otp.c
@@ -1619,7 +1619,6 @@ int decrypt_text_silent(const char* pad_identifier, const char* encrypted_messag
|
|||||||
// For piped decrypt mode - silent operation with minimal output
|
// For piped decrypt mode - silent operation with minimal output
|
||||||
(void)pad_identifier; // Suppress unused parameter warning
|
(void)pad_identifier; // Suppress unused parameter warning
|
||||||
|
|
||||||
char line[MAX_LINE_LENGTH];
|
|
||||||
char stored_chksum[MAX_HASH_LENGTH];
|
char stored_chksum[MAX_HASH_LENGTH];
|
||||||
char current_chksum[MAX_HASH_LENGTH];
|
char current_chksum[MAX_HASH_LENGTH];
|
||||||
uint64_t pad_offset;
|
uint64_t pad_offset;
|
||||||
@@ -2612,7 +2611,7 @@ int load_preferences(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char preferences_dir[1024];
|
char preferences_dir[1024];
|
||||||
char preferences_file[1024];
|
char preferences_file[2048]; // Increased buffer size to accommodate longer paths
|
||||||
snprintf(preferences_dir, sizeof(preferences_dir), "%s/.otp", home_dir);
|
snprintf(preferences_dir, sizeof(preferences_dir), "%s/.otp", home_dir);
|
||||||
snprintf(preferences_file, sizeof(preferences_file), "%s/otp.conf", preferences_dir);
|
snprintf(preferences_file, sizeof(preferences_file), "%s/otp.conf", preferences_dir);
|
||||||
|
|
||||||
@@ -2660,7 +2659,7 @@ int save_preferences(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char preferences_dir[1024];
|
char preferences_dir[1024];
|
||||||
char preferences_file[1024];
|
char preferences_file[2048]; // Increased buffer size to accommodate longer paths
|
||||||
snprintf(preferences_dir, sizeof(preferences_dir), "%s/.otp", home_dir);
|
snprintf(preferences_dir, sizeof(preferences_dir), "%s/.otp", home_dir);
|
||||||
snprintf(preferences_file, sizeof(preferences_file), "%s/otp.conf", preferences_dir);
|
snprintf(preferences_file, sizeof(preferences_file), "%s/otp.conf", preferences_dir);
|
||||||
|
|
||||||
@@ -2733,7 +2732,7 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
|
|||||||
while ((mount_entry = readdir(mount_dir)) != NULL) {
|
while ((mount_entry = readdir(mount_dir)) != NULL) {
|
||||||
if (mount_entry->d_name[0] == '.') continue;
|
if (mount_entry->d_name[0] == '.') continue;
|
||||||
|
|
||||||
char mount_path[512];
|
char mount_path[1024]; // Increased buffer size
|
||||||
snprintf(mount_path, sizeof(mount_path), "%s/%s", mount_dirs[mount_idx], mount_entry->d_name);
|
snprintf(mount_path, sizeof(mount_path), "%s/%s", mount_dirs[mount_idx], mount_entry->d_name);
|
||||||
|
|
||||||
// For /media, we need to go one level deeper (user directories)
|
// For /media, we need to go one level deeper (user directories)
|
||||||
@@ -2749,7 +2748,11 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
|
|||||||
// Check if drive name starts with "OTP"
|
// Check if drive name starts with "OTP"
|
||||||
if (strncmp(user_entry->d_name, "OTP", 3) != 0) continue;
|
if (strncmp(user_entry->d_name, "OTP", 3) != 0) continue;
|
||||||
|
|
||||||
char user_mount_path[512];
|
char user_mount_path[1024]; // Increased buffer size
|
||||||
|
// Verify buffer has enough space before concatenation
|
||||||
|
size_t mount_len = strlen(mount_path);
|
||||||
|
size_t entry_len = strlen(user_entry->d_name);
|
||||||
|
if (mount_len + entry_len + 2 < sizeof(user_mount_path)) {
|
||||||
snprintf(user_mount_path, sizeof(user_mount_path), "%s/%s", mount_path, user_entry->d_name);
|
snprintf(user_mount_path, sizeof(user_mount_path), "%s/%s", mount_path, user_entry->d_name);
|
||||||
|
|
||||||
// Check if this is a readable directory
|
// Check if this is a readable directory
|
||||||
@@ -2763,6 +2766,7 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
|
|||||||
return 1; // Found OTP drive
|
return 1; // Found OTP drive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
closedir(user_dir);
|
closedir(user_dir);
|
||||||
} else if (strcmp(mount_dirs[mount_idx], "/run/media") == 0) {
|
} else if (strcmp(mount_dirs[mount_idx], "/run/media") == 0) {
|
||||||
// For /run/media, we need to go one level deeper (skip username)
|
// For /run/media, we need to go one level deeper (skip username)
|
||||||
@@ -3393,7 +3397,7 @@ int handle_pads_menu(void) {
|
|||||||
pads[pad_count].chksum[64] = '\0';
|
pads[pad_count].chksum[64] = '\0';
|
||||||
|
|
||||||
// Get pad file size and usage info
|
// Get pad file size and usage info
|
||||||
char full_path[512];
|
char full_path[1024]; // Increased buffer size
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user