Skip to content

Commit dad84d8

Browse files
authored
Merge pull request #99 from opensensor/copilot/fix-function-visibility-modifiers
Fix function visibility, magic numbers, AbortController bug, and localStorage credential leak
2 parents a4f007b + 2db4a2d commit dad84d8

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/storage/storage_manager.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@
2626
// Maximum recordings to delete per stream per run
2727
#define MAX_RECORDINGS_PER_STREAM 100
2828

29+
// Default retention period (in days) when no global or stream-specific value is configured
30+
#define DEFAULT_RETENTION_DAYS 30
31+
// Multiplier for detection retention default (detection = N * regular retention)
32+
#define DETECTION_RETENTION_MULTIPLIER 3
33+
// Orphan safety parameters
34+
#define ORPHAN_SAFETY_THRESHOLD 0.5
35+
#define MIN_RECORDINGS_FOR_THRESHOLD 10
36+
2937
// Forward declarations
3038
static int apply_legacy_retention_policy(void);
31-
int get_all_stream_names(char stream_names[][64], int max_streams);
39+
static int get_all_stream_names(char stream_names[][64], int max_streams);
3240

3341
// Storage manager state
3442
static struct {
@@ -274,8 +282,8 @@ int apply_retention_policy(void) {
274282
// Get stream-specific retention config
275283
if (get_stream_retention_config(stream_name, &config) != 0) {
276284
log_warn("Failed to get retention config for stream %s, using defaults", stream_name);
277-
config.retention_days = storage_manager.retention_days > 0 ? storage_manager.retention_days : 30;
278-
config.detection_retention_days = config.retention_days * 3; // Default: 3x regular retention
285+
config.retention_days = storage_manager.retention_days > 0 ? storage_manager.retention_days : DEFAULT_RETENTION_DAYS;
286+
config.detection_retention_days = config.retention_days * DETECTION_RETENTION_MULTIPLIER; // Default: 3x regular retention
279287
config.max_storage_mb = 0; // No quota
280288
}
281289

@@ -401,7 +409,8 @@ int apply_retention_policy(void) {
401409
// Safety threshold: if more than 50% of checked recordings appear orphaned,
402410
// this is almost certainly a storage availability problem, not genuine orphans.
403411
double orphan_ratio = (double)orphan_count / (double)total_checked;
404-
if (orphan_ratio > 0.5 && total_checked >= 10) {
412+
if (orphan_ratio > ORPHAN_SAFETY_THRESHOLD &&
413+
total_checked >= MIN_RECORDINGS_FOR_THRESHOLD) {
405414
log_error("Orphan safety threshold exceeded: %d of %d checked recordings (%.0f%%) "
406415
"appear orphaned - this likely indicates a storage availability issue, "
407416
"skipping orphan cleanup to protect database integrity",
@@ -587,9 +596,6 @@ int create_stream_directory(const char *stream_name) {
587596
// Maximum recordings to process per emergency cleanup
588597
#define MAX_EMERGENCY_RECORDINGS 200
589598

590-
// Forward declaration for the cache refresh function
591-
extern int force_refresh_cache(void);
592-
593599
// Unified storage controller thread state
594600
static struct {
595601
pthread_t thread;

web/js/components/preact/LoginView.jsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ export function LoginView() {
116116
if (abortControllerRef.current) {
117117
abortControllerRef.current.abort();
118118
}
119-
const abortController = new AbortController();
120-
abortControllerRef.current = abortController;
121119

122120
setIsLoggingIn(true);
123121
setErrorMessage('');
@@ -133,6 +131,7 @@ export function LoginView() {
133131

134132
// Make login request with an explicit timeout using AbortController
135133
const controller = new AbortController();
134+
abortControllerRef.current = controller;
136135
const timeoutId = setTimeout(() => controller.abort(), 10000);
137136

138137
let response;
@@ -165,9 +164,6 @@ export function LoginView() {
165164
// Successful login (no TOTP required or force MFA verified)
166165
console.log('Login successful, proceeding to redirect');
167166

168-
// Store credentials in localStorage for future requests, now that authentication succeeded
169-
localStorage.setItem('auth', authString);
170-
171167
// Redirect to the requested page, or the index if none / unsafe.
172168
const urlParams = new URLSearchParams(window.location.search);
173169
window.location.href = safeRedirectPath(urlParams.get('redirect'));
@@ -179,7 +175,6 @@ export function LoginView() {
179175
} else {
180176
setErrorMessage('Invalid credentials');
181177
}
182-
localStorage.removeItem('auth');
183178
if (forceMfaEnabled) {
184179
setForceMfaTotpCode('');
185180
}
@@ -189,7 +184,6 @@ export function LoginView() {
189184
// Reset login state on error
190185
setIsLoggingIn(false);
191186
setErrorMessage('An error occurred during login. Please try again.');
192-
localStorage.removeItem('auth');
193187
}
194188
};
195189

0 commit comments

Comments
 (0)