|
1
|
# |
|
2
|
# Copyright (c) 2025 D. Richard Hipp |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
# Author contact information: |
|
13
|
# [email protected] |
|
14
|
# http://www.hwaci.com/drh/ |
|
15
|
# |
|
16
|
############################################################################ |
|
17
|
# |
|
18
|
# TH1 Commands |
|
19
|
# |
|
20
|
|
|
21
|
set path [file dirname [info script]]; test_setup |
|
22
|
|
|
23
|
proc taint-test {testnum th1script expected} { |
|
24
|
global fossilexe |
|
25
|
set rc [catch {exec $fossilexe test-th-eval $th1script} got] |
|
26
|
if {$rc} { |
|
27
|
test th1-taint-$testnum 0 |
|
28
|
puts $got |
|
29
|
return |
|
30
|
} |
|
31
|
if {$got ne $expected} { |
|
32
|
test th1-taint-$testnum 0 |
|
33
|
puts " Expected: $expected" |
|
34
|
puts " Got: $got" |
|
35
|
} else { |
|
36
|
test th1-taint-$testnum 1 |
|
37
|
} |
|
38
|
} |
|
39
|
|
|
40
|
taint-test 10 {string is tainted abcd} 0 |
|
41
|
taint-test 20 {string is tainted [taint abcd]} 1 |
|
42
|
taint-test 30 {string is tainted [untaint [taint abcd]]} 0 |
|
43
|
taint-test 40 {string is tainted [untaint abcde]} 0 |
|
44
|
taint-test 50 {string is tainted "abc[taint def]ghi"} 1 |
|
45
|
taint-test 60 {set t1 [taint abc]; string is tainted "123 $t1 456"} 1 |
|
46
|
|
|
47
|
taint-test 100 {set t1 [taint abc]; lappend t1 def; string is tainted $t1} 1 |
|
48
|
taint-test 110 {set t1 abc; lappend t1 [taint def]; string is tainted $t1} 1 |
|
49
|
|
|
50
|
taint-test 200 {string is tainted [list abc def ghi]} 0 |
|
51
|
taint-test 210 {string is tainted [list [taint abc] def ghi]} 1 |
|
52
|
taint-test 220 {string is tainted [list abc [taint def] ghi]} 1 |
|
53
|
taint-test 230 {string is tainted [list abc def [taint ghi]]} 1 |
|
54
|
|
|
55
|
taint-test 300 { |
|
56
|
set res {} |
|
57
|
foreach x [list abc [taint def] ghi] { |
|
58
|
lappend res [string is tainted $x] |
|
59
|
} |
|
60
|
set res |
|
61
|
} {1 1 1} |
|
62
|
taint-test 310 { |
|
63
|
set res {} |
|
64
|
foreach {x y} [list abc [taint def] ghi jkl] { |
|
65
|
lappend res [string is tainted $x] [string is tainted $y] |
|
66
|
} |
|
67
|
set res |
|
68
|
} {1 1 1 1} |
|
69
|
|
|
70
|
taint-test 400 {string is tainted [lindex "abc [taint def] ghi" 0]} 1 |
|
71
|
taint-test 410 {string is tainted [lindex "abc [taint def] ghi" 1]} 1 |
|
72
|
taint-test 420 {string is tainted [lindex "abc [taint def] ghi" 2]} 1 |
|
73
|
taint-test 430 {string is tainted [lindex "abc [taint def] ghi" 3]} 0 |
|
74
|
|
|
75
|
taint-test 500 {string is tainted [string index [taint abcdefg] 3]} 1 |
|
76
|
|
|
77
|
taint-test 600 {string is tainted [string range [taint abcdefg] 3 5]} 1 |
|
78
|
|
|
79
|
taint-test 700 {string is tainted [string trim [taint " abcdefg "]]} 1 |
|
80
|
taint-test 710 {string is tainted [string trimright [taint " abcdefg "]]} 1 |
|
81
|
taint-test 720 {string is tainted [string trimleft [taint " abcdefg "]]} 1 |
|
82
|
|
|
83
|
|
|
84
|
test_cleanup |
|
85
|
|