This commit addresses concerns raised by AI code reviewers (gemini-code-assist,
Copilot, coderabbitai) on the initial security fixes.
Critical fixes:
- Fix lock.release() → lock.unlock() in GenAI_Thread.cpp worker_loop
(lock.release() detaches without unlocking, causing deadlock)
- Add missing early return after schema validation failure in Query_Tool_Handler.cpp
Code quality improvements:
- Improve escape_string() memory management in MySQL_Tool_Handler.cpp:
- Use std::string instead of new[]/delete[] for buffer management
- Check return value of mysql_real_escape_string() for errors
- Remove redundant validation checks in validate_sql_identifier functions
(character class loop already rejects unsafe characters)
- Add backslash escaping to escape_string_literal() for defense-in-depth
- Improve column list validation in MySQL_Tool_Handler sample_rows():
- Replace blacklist approach with proper column identifier parsing
- Allow qualified identifiers (table.column)
- Allow AS aliases (column AS alias)
- No longer rejects legitimate column names containing "JOIN"
These changes improve robustness while maintaining the security posture
of the original SQL injection fixes.