af0aeebb6fbccc3364ce3c85e7052baa2b124f10
braney
  Tue Aug 11 09:22:17 2026 -0700
hg/lib/tests: add a sqlCheck case for the 0x01 escape marker bypass, refs #38051

New XM type wraps the given value in the 0x01 marker that sqlSafef uses
internally to delimit the spans it must escape, then calls sqlSafef. Two markers
forge an extra delimiter pair and used to leave the text between them unescaped,
so this must now abort.

The payload is built inside sqlCheck.c rather than passed in from the makefile,
so the test does not need a control byte in a shell argument.

This case passes whether or not HGDB_CONF is set, because the guard it exercises
uses a hard errAbort rather than sqlCheckError. Note that sqlCheck is not in the
default test target, and that case 3 does need HGDB_CONF set in order to abort.

diff --git src/hg/lib/tests/sqlCheck.mk src/hg/lib/tests/sqlCheck.mk
index 85c0047ff59..4f5b666d8c2 100644
--- src/hg/lib/tests/sqlCheck.mk
+++ src/hg/lib/tests/sqlCheck.mk
@@ -1,35 +1,37 @@
 # makefile with sqlCheck tests
 include ../../../inc/common.mk
 include testCommon.mk
 
 TEST = sqlCheck
 TESTER = ${BIN_DIR}/sqlCheck
 IN = ${IN_DIR}/${TEST}
 EXP = ${EXP_DIR}/${TEST}
 OUT = ${OUT_DIR}/${TEST}
 
 test: simpleTest
 
 # ID should only allow alphanum . _ (spaces are not allowed of course)
 # QL should allow any values except the special chars that require escaping such as quotes or backSlash
 # ES should escape the string at the cost of making the mysql escape call, but allows all chars.
 # EE just provides a handy way to add all the evil forbidden chars to your test string so you can see them get escaped.
 
 simpleTest: mkout
 	${TESTER} ID 'myTable' > ${OUT}/sqlCheck.1
 	diff ${OUT}/sqlCheck.1 ${EXP}/sqlCheck.1
 	${TESTER} ID 'hg19.my_Table' > ${OUT}/sqlCheck.2
 	diff ${OUT}/sqlCheck.2 ${EXP}/sqlCheck.2
 	-${TESTER} ID 'my Table' 2>&1 | grep -v '0x' >& ${OUT}/sqlCheck.3
 	diff ${OUT}/sqlCheck.3 ${EXP}/sqlCheck.3
 	-${TESTER} ID "'myTable" 2>&1 | grep -v '0x' >& ${OUT}/sqlCheck.4
 	diff ${OUT}/sqlCheck.4 ${EXP}/sqlCheck.4
 	${TESTER} ES 'my "Table' >& ${OUT}/sqlCheck.7
 	diff ${OUT}/sqlCheck.7 ${EXP}/sqlCheck.7
 	${TESTER} EE "" >& ${OUT}/sqlCheck.8
 	diff ${OUT}/sqlCheck.8 ${EXP}/sqlCheck.8
 	${TESTER} IL "chromStart,chromEnd,'.',score" >& ${OUT}/sqlCheck.9
 	diff ${OUT}/sqlCheck.9 ${EXP}/sqlCheck.9
+	-${TESTER} XM "' OR '1'='1" 2>&1 | grep -v '0x' >& ${OUT}/sqlCheck.10
+	diff ${OUT}/sqlCheck.10 ${EXP}/sqlCheck.10
 
 mkout:
 	@${MKDIR} ${OUT}