Merge pull request #20 from m1ngsama/fix/edge-cases-and-robustness

Fix edge cases in message loading and network I/O
This commit is contained in:
m1ngsama 2026-04-19 17:38:51 +08:00 committed by GitHub
commit 83e964028a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -61,7 +61,7 @@ int message_load(message_t **messages, int max_messages) {
} }
long file_size = ftell(fp); long file_size = ftell(fp);
if (file_size == 0) { if (file_size <= 0) {
fclose(fp); fclose(fp);
*messages = msg_array; *messages = msg_array;
return 0; return 0;

View file

@ -195,8 +195,10 @@ static ip_rate_limit_t* get_rate_limit_entry(const char *ip) {
oldest_idx = i; oldest_idx = i;
} }
} }
fprintf(stderr, "Warning: rate-limit table full, evicting active IP %s\n", fprintf(stderr, "Warning: rate-limit table full, evicting active IP %s "
g_rate_limits[oldest_idx].ip); "(%d active connections lost)\n",
g_rate_limits[oldest_idx].ip,
g_rate_limits[oldest_idx].active_connections);
} }
/* Reset and reuse */ /* Reset and reuse */
@ -488,7 +490,9 @@ int client_send(client_t *client, const char *data, size_t len) {
} }
while (total < len) { while (total < len) {
int sent = ssh_channel_write(client->channel, data + total, len - total); size_t remaining = len - total;
uint32_t chunk = (remaining > 32768) ? 32768 : (uint32_t)remaining;
int sent = ssh_channel_write(client->channel, data + total, chunk);
if (sent <= 0) { if (sent <= 0) {
pthread_mutex_unlock(&client->io_lock); pthread_mutex_unlock(&client->io_lock);
return -1; return -1;