|
1 | | -// semmle-extractor-options: /r:System.Text.RegularExpressions.dll /r:System.Collections.Specialized.dll /r:System.Net.dll /r:System.Web.dll /r:System.Net.HttpListener.dll /r:System.Collections.Specialized.dll /r:System.Private.Uri.dll /r:System.Runtime.Extensions.dll /r:System.Linq.Parallel.dll /r:System.Collections.Concurrent.dll /r:System.Linq.Expressions.dll /r:System.Collections.dll /r:System.Linq.Queryable.dll /r:System.Linq.dll /r:System.Collections.NonGeneric.dll /r:System.ObjectModel.dll /r:System.ComponentModel.TypeConverter.dll /r:System.IO.Compression.dll /r:System.IO.Pipes.dll /r:System.Net.Primitives.dll /r:System.Net.Security.dll /r:System.Security.Cryptography.Primitives.dll /r:System.Text.RegularExpressions.dll ${testdir}/../../resources/stubs/System.Web.cs /r:System.Runtime.Serialization.Primitives.dll |
2 | | - |
3 | | -using System; |
4 | | -using System.IO; |
5 | | -using System.Text; |
6 | | -using System.Collections; |
7 | | -using System.Collections.Generic; |
8 | | -using System.Collections.Specialized; |
9 | | -using System.Linq; |
10 | | -using System.Runtime.Serialization; |
11 | | -using System.Threading.Tasks; |
12 | | -using System.Web; |
13 | | -using System.Web.UI.WebControls; |
14 | | -using System.Text.RegularExpressions; |
15 | | - |
16 | | -public class RegexHandler |
17 | | -{ |
18 | | - private static readonly string JAVA_CLASS_REGEX = "^(([a-z])+.)+[A-Z]([a-z])+$"; |
19 | | - |
20 | | - public void ProcessRequest() |
21 | | - { |
22 | | - string userInput = ""; |
23 | | - |
24 | | - // BAD: |
25 | | - // Artificial regexes |
26 | | - new Regex("^([a-z]+)+$").Match(userInput); |
27 | | - new Regex("^([a-z]*)*$").Replace(userInput, ""); |
28 | | - // Known exponential blowup regex for e-mail address validation |
29 | | - // Problematic part is: ([a-zA-Z0-9]+))* |
30 | | - new Regex("^([a-zA-Z0-9])(([\\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$").Match(userInput); |
31 | | - // Known exponential blowup regex for Java class name validation |
32 | | - // Problematic part is: (([a-z])+.)+ |
33 | | - new Regex(JAVA_CLASS_REGEX).Match(userInput); |
34 | | - // Static use |
35 | | - Regex.Match(userInput, JAVA_CLASS_REGEX); |
36 | | - // GOOD: |
37 | | - new Regex("^(([a-b]+[c-z]+)+$").Match(userInput); |
38 | | - new Regex("^([a-z]+)+$", RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1)).Match(userInput); |
39 | | - Regex.Match(userInput, JAVA_CLASS_REGEX, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1)); |
40 | | - // Known possible FP. |
41 | | - new Regex("^[a-z0-9]+([_.-][a-z0-9]+)*$").Match(userInput); |
42 | | - } |
43 | | -} |
44 | | - |
45 | | -// The only purpose of this class is to make sure the extractor extracts the |
46 | | -// relevant library methods |
47 | | -public class LibraryTypeDataFlow |
48 | | -{ |
49 | | - void M() |
50 | | - { |
51 | | - int i; |
52 | | - int.Parse(""); |
53 | | - int.TryParse("", out i); |
54 | | - |
55 | | - bool b; |
56 | | - bool.Parse(""); |
57 | | - bool.TryParse("", out b); |
58 | | - |
59 | | - Uri uri = null; |
60 | | - uri.ToString(); |
61 | | - |
62 | | - StringReader sr = new StringReader(""); |
63 | | - |
64 | | - string s = new string(new[] { 'a' }); |
65 | | - string.Join("", "", "", ""); |
66 | | - |
67 | | - StringBuilder sb = new StringBuilder(""); |
68 | | - |
69 | | - Lazy<int> l = new Lazy<int>(() => 42); |
70 | | - |
71 | | - IEnumerable ie = null; |
72 | | - ie.GetEnumerator(); |
73 | | - ie.AsParallel(); |
74 | | - ie.AsQueryable(); |
75 | | - IEnumerable<int> ieint = null; |
76 | | - ieint.Select(x => x); |
77 | | - List<int> list = null; |
78 | | - list.Find(x => x > 0); |
79 | | - Stack<int> stack = null; |
80 | | - stack.Peek(); |
81 | | - ArrayList al = null; |
82 | | - ArrayList.FixedSize(al); |
83 | | - SortedList sl = null; |
84 | | - sl.GetByIndex(0); |
85 | | - |
86 | | - Convert.ToInt32("0"); |
87 | | - |
88 | | - DataContract dc = null; |
89 | | - s = dc.AString; |
90 | | - |
91 | | - KeyValuePair<int, string> kvp = new KeyValuePair<int, string>(0, ""); |
92 | | - |
93 | | - IEnumerator ienum = null; |
94 | | - object o = ienum.Current; |
95 | | - |
96 | | - IEnumerator<int> ienumint = null; |
97 | | - i = ienumint.Current; |
98 | | - |
99 | | - var task = new Task(() => { }); |
100 | | - Task.WhenAll<int>(null, null); |
101 | | - Task.WhenAny<int>(null, null); |
102 | | - Task.Factory.ContinueWhenAll((Task[])null, (Func<Task[], int>)null); |
103 | | - |
104 | | - var task2 = new Task<int>(() => 42); |
105 | | - Task<string>.Factory.ContinueWhenAny<int>(new Task<int>[] { task2 }, t => t.Result.ToString()); |
106 | | - |
107 | | - Encoding.Unicode.GetString(Encoding.Unicode.GetBytes("")); |
108 | | - |
109 | | - Path.Combine("", ""); |
110 | | - Path.GetDirectoryName(""); |
111 | | - Path.GetExtension(""); |
112 | | - Path.GetFileName(""); |
113 | | - Path.GetFileNameWithoutExtension(""); |
114 | | - Path.GetPathRoot(""); |
115 | | - HttpContextBase context = null; |
116 | | - string name = context.Request.QueryString["name"]; |
117 | | - } |
118 | | - |
119 | | - [DataContract] |
120 | | - public class DataContract |
121 | | - { |
122 | | - [DataMember] |
123 | | - public string AString { get; set; } |
124 | | - } |
125 | | -} |
| 1 | +// semmle-extractor-options: /r:System.Text.RegularExpressions.dll /r:System.Collections.Specialized.dll /r:System.Net.dll /r:System.Web.dll /r:System.Net.HttpListener.dll /r:System.Collections.Specialized.dll /r:System.Private.Uri.dll /r:System.Runtime.Extensions.dll /r:System.Linq.Parallel.dll /r:System.Collections.Concurrent.dll /r:System.Linq.Expressions.dll /r:System.Collections.dll /r:System.Linq.Queryable.dll /r:System.Linq.dll /r:System.Collections.NonGeneric.dll /r:System.ObjectModel.dll /r:System.ComponentModel.TypeConverter.dll /r:System.IO.Compression.dll /r:System.IO.Pipes.dll /r:System.Net.Primitives.dll /r:System.Net.Security.dll /r:System.Security.Cryptography.Primitives.dll /r:System.Text.RegularExpressions.dll ${testdir}/../../resources/stubs/System.Web.cs /r:System.Runtime.Serialization.Primitives.dll |
| 2 | + |
| 3 | +using System; |
| 4 | +using System.IO; |
| 5 | +using System.Text; |
| 6 | +using System.Collections; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Collections.Specialized; |
| 9 | +using System.Linq; |
| 10 | +using System.Runtime.Serialization; |
| 11 | +using System.Threading.Tasks; |
| 12 | +using System.Web; |
| 13 | +using System.Web.UI.WebControls; |
| 14 | +using System.Text.RegularExpressions; |
| 15 | + |
| 16 | +public class RegexHandler |
| 17 | +{ |
| 18 | + private static readonly string JAVA_CLASS_REGEX = "^(([a-z])+.)+[A-Z]([a-z])+$"; |
| 19 | + |
| 20 | + public void ProcessRequest() |
| 21 | + { |
| 22 | + string userInput = ""; |
| 23 | + |
| 24 | + // BAD: |
| 25 | + // Artificial regexes |
| 26 | + new Regex("^([a-z]+)+$").Match(userInput); |
| 27 | + new Regex("^([a-z]*)*$").Replace(userInput, ""); |
| 28 | + // Known exponential blowup regex for e-mail address validation |
| 29 | + // Problematic part is: ([a-zA-Z0-9]+))* |
| 30 | + new Regex("^([a-zA-Z0-9])(([\\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$").Match(userInput); |
| 31 | + // Known exponential blowup regex for Java class name validation |
| 32 | + // Problematic part is: (([a-z])+.)+ |
| 33 | + new Regex(JAVA_CLASS_REGEX).Match(userInput); |
| 34 | + // Static use |
| 35 | + Regex.Match(userInput, JAVA_CLASS_REGEX); |
| 36 | + // GOOD: |
| 37 | + new Regex("^(([a-b]+[c-z]+)+$").Match(userInput); |
| 38 | + new Regex("^([a-z]+)+$", RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1)).Match(userInput); |
| 39 | + Regex.Match(userInput, JAVA_CLASS_REGEX, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1)); |
| 40 | + // Known possible FP. |
| 41 | + new Regex("^[a-z0-9]+([_.-][a-z0-9]+)*$").Match(userInput); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +// The only purpose of this class is to make sure the extractor extracts the |
| 46 | +// relevant library methods |
| 47 | +public class LibraryTypeDataFlow |
| 48 | +{ |
| 49 | + void M() |
| 50 | + { |
| 51 | + int i; |
| 52 | + int.Parse(""); |
| 53 | + int.TryParse("", out i); |
| 54 | + |
| 55 | + bool b; |
| 56 | + bool.Parse(""); |
| 57 | + bool.TryParse("", out b); |
| 58 | + |
| 59 | + Uri uri = null; |
| 60 | + uri.ToString(); |
| 61 | + |
| 62 | + StringReader sr = new StringReader(""); |
| 63 | + |
| 64 | + string s = new string(new[] { 'a' }); |
| 65 | + string.Join("", "", "", ""); |
| 66 | + |
| 67 | + StringBuilder sb = new StringBuilder(""); |
| 68 | + |
| 69 | + Lazy<int> l = new Lazy<int>(() => 42); |
| 70 | + |
| 71 | + IEnumerable ie = null; |
| 72 | + ie.GetEnumerator(); |
| 73 | + ie.AsParallel(); |
| 74 | + ie.AsQueryable(); |
| 75 | + IEnumerable<int> ieint = null; |
| 76 | + ieint.Select(x => x); |
| 77 | + List<int> list = null; |
| 78 | + list.Find(x => x > 0); |
| 79 | + Stack<int> stack = null; |
| 80 | + stack.Peek(); |
| 81 | + ArrayList al = null; |
| 82 | + ArrayList.FixedSize(al); |
| 83 | + SortedList sl = null; |
| 84 | + sl.GetByIndex(0); |
| 85 | + |
| 86 | + Convert.ToInt32("0"); |
| 87 | + |
| 88 | + DataContract dc = null; |
| 89 | + s = dc.AString; |
| 90 | + |
| 91 | + KeyValuePair<int, string> kvp = new KeyValuePair<int, string>(0, ""); |
| 92 | + |
| 93 | + IEnumerator ienum = null; |
| 94 | + object o = ienum.Current; |
| 95 | + |
| 96 | + IEnumerator<int> ienumint = null; |
| 97 | + i = ienumint.Current; |
| 98 | + |
| 99 | + var task = new Task(() => { }); |
| 100 | + Task.WhenAll<int>(null, null); |
| 101 | + Task.WhenAny<int>(null, null); |
| 102 | + Task.Factory.ContinueWhenAll((Task[])null, (Func<Task[], int>)null); |
| 103 | + |
| 104 | + var task2 = new Task<int>(() => 42); |
| 105 | + Task<string>.Factory.ContinueWhenAny<int>(new Task<int>[] { task2 }, t => t.Result.ToString()); |
| 106 | + |
| 107 | + Encoding.Unicode.GetString(Encoding.Unicode.GetBytes("")); |
| 108 | + |
| 109 | + Path.Combine("", ""); |
| 110 | + Path.GetDirectoryName(""); |
| 111 | + Path.GetExtension(""); |
| 112 | + Path.GetFileName(""); |
| 113 | + Path.GetFileNameWithoutExtension(""); |
| 114 | + Path.GetPathRoot(""); |
| 115 | + HttpContextBase context = null; |
| 116 | + string name = context.Request.QueryString["name"]; |
| 117 | + } |
| 118 | + |
| 119 | + [DataContract] |
| 120 | + public class DataContract |
| 121 | + { |
| 122 | + [DataMember] |
| 123 | + public string AString { get; set; } |
| 124 | + } |
| 125 | +} |
0 commit comments