mirror of
https://oauth2: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@github.com/m1ngsama/TNT.git
synced 2026-05-10 19:00:57 +08:00
Critical fixes: - C-1: Use atomic_bool for client->connected and redraw_pending to prevent data races between callback and main threads - C-2: Add reference counting for channel callbacks to prevent use-after-free when callbacks fire during client cleanup - C-3/M-7: Use ssh_channel_read_timeout (5s) for UTF-8 continuation bytes to prevent thread blocking and stream desynchronization High-severity fixes: - H-1: Replace non-thread-safe setenv/tzset with timegm() in parse_rfc3339_utc - H-2: Change room_get_message to return by value copy instead of interior pointer - H-3: Log warning when rate-limit table evicts active IP entry - H-4: Replace strcmp with constant-time comparison for access token validation - H-5: Check signature_state in auth_pubkey to reject unsigned key offers Medium/low fixes: - M-1: Replace all atoi() with strtol() for proper error detection - M-3: Move calloc outside rwlock in tui_render_screen to avoid blocking writers - M-8: Fix off-by-one in rate limit threshold (> to >=) - M-9: Trim partial UTF-8 sequences after snprintf truncation in message_format - L-1: Validate continuation byte mask (0xC0==0x80) in utf8_decode - D-3: Remove vestigial client_t.fd field - L-3: Remove unreachable pthread_attr_destroy after infinite loop
55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
#ifndef COMMON_H
|
|
#define COMMON_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stdatomic.h>
|
|
#include <time.h>
|
|
#include <limits.h>
|
|
#include <pthread.h>
|
|
|
|
/* Project Metadata */
|
|
#define TNT_VERSION "1.0.0"
|
|
|
|
/* Configuration constants */
|
|
#define DEFAULT_PORT 2222
|
|
#define MAX_MESSAGES 100
|
|
#define MAX_USERNAME_LEN 64
|
|
#define MAX_MESSAGE_LEN 1024
|
|
#define MAX_EXEC_COMMAND_LEN 1024
|
|
#define MAX_CLIENTS 64
|
|
#define LOG_FILE "messages.log"
|
|
#define HOST_KEY_FILE "host_key"
|
|
#define TNT_DEFAULT_STATE_DIR "."
|
|
|
|
/* ANSI color codes */
|
|
#define ANSI_RESET "\033[0m"
|
|
#define ANSI_BOLD "\033[1m"
|
|
#define ANSI_REVERSE "\033[7m"
|
|
#define ANSI_CLEAR "\033[2J"
|
|
#define ANSI_HOME "\033[H"
|
|
#define ANSI_CLEAR_LINE "\033[K"
|
|
|
|
/* Operating modes */
|
|
typedef enum {
|
|
MODE_INSERT,
|
|
MODE_NORMAL,
|
|
MODE_COMMAND,
|
|
MODE_HELP
|
|
} client_mode_t;
|
|
|
|
/* Help language */
|
|
typedef enum {
|
|
LANG_EN,
|
|
LANG_ZH
|
|
} help_lang_t;
|
|
|
|
/* Runtime helpers */
|
|
const char* tnt_state_dir(void);
|
|
int tnt_ensure_state_dir(void);
|
|
int tnt_state_path(char *buffer, size_t buf_size, const char *filename);
|
|
|
|
#endif /* COMMON_H */
|