Skip to content

Commit cb7a85b

Browse files
Merge pull request #75 from dreamer-coding/main
Bug hunt patch
2 parents d29ca65 + b6706cd commit cb7a85b

18 files changed

+5399
-243
lines changed

code/logic/input.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,26 @@ int fossil_io_validate_sanitize_string(const char *input,
324324
flags |= FOSSIL_SAN_BASE64;
325325

326326
/* Sanitization pass */
327+
int modified = 0;
327328
for (size_t i = 0; i < in_len && out_i < output_size - 1; i++) {
328329
char c = input[i];
329330
if (is_allowed(c)) {
330331
output[out_i++] = c;
331332
} else {
332333
output[out_i++] = '_'; /* neutralize */
333-
flags |= FOSSIL_SAN_MODIFIED;
334+
modified = 1;
334335
}
335336
}
336337
output[out_i] = '\0';
337338

339+
/* Edge case: SQL context, but input contains SQL keywords with only allowed chars */
340+
if ((ctx == FOSSIL_CTX_SQL) && (flags & FOSSIL_SAN_SQL) && !modified) {
341+
/* Force MODIFIED if SQL pattern detected but no chars were replaced */
342+
flags |= FOSSIL_SAN_MODIFIED;
343+
} else if (modified) {
344+
flags |= FOSSIL_SAN_MODIFIED;
345+
}
346+
338347
return flags == 0 ? FOSSIL_SAN_OK : flags;
339348
}
340349

@@ -638,13 +647,15 @@ int fossil_io_validate_is_email(const char *input) {
638647

639648
// Check for the presence of an '@' character
640649
const char *at = strchr(input, '@');
641-
if (at == NULL) {
650+
if (at == NULL || at == input) {
651+
// No '@' or no local part before '@'
642652
return 0;
643653
}
644654

645655
// Check for the presence of a '.' character after the '@' character
646656
const char *dot = strchr(at, '.');
647-
if (dot == NULL) {
657+
if (dot == NULL || dot == at + 1) {
658+
// No '.' after '@' or nothing between '@' and '.'
648659
return 0;
649660
}
650661

0 commit comments

Comments
 (0)