Skip to content

Commit 6689280

Browse files
committed
Merge branch 'main' into marcono1234/deprecate-StringLiteral-getRepresentedString
2 parents b284e72 + e88bbfd commit 6689280

File tree

41 files changed

+700
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+700
-97
lines changed

docs/codeql/support/reusables/frameworks.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ Python built-in support
171171
multidict, Utility library
172172
yarl, Utility library
173173
aioch, Database
174+
asyncpg, Database
174175
clickhouse-driver, Database
175176
mysql-connector-python, Database
176177
mysql-connector, Database
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Added data flow models for lambda methods on `java.util.Optional`.

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,15 @@ class CompileTimeConstantExpr extends Expr {
298298
*
299299
* Note that this does not handle the following cases:
300300
*
301-
* - values of type `long`,
302-
* - `char` literals.
301+
* - values of type `long`.
303302
*/
304303
cached
305304
int getIntValue() {
306305
exists(IntegralType t | this.getType() = t | t.getName().toLowerCase() != "long") and
307306
(
308-
exists(string lit | lit = this.(Literal).getValue() |
309-
// `char` literals may get parsed incorrectly, so disallow.
310-
not this instanceof CharacterLiteral and
311-
result = lit.toInt()
312-
)
307+
result = this.(IntegerLiteral).getIntValue()
308+
or
309+
result = this.(CharacterLiteral).getCodePointValue()
313310
or
314311
exists(CastExpr cast, int val |
315312
cast = this and val = cast.getExpr().(CompileTimeConstantExpr).getIntValue()
@@ -719,6 +716,22 @@ class DoubleLiteral extends Literal, @doubleliteral {
719716
/** A character literal. For example, `'\n'`. */
720717
class CharacterLiteral extends Literal, @characterliteral {
721718
override string getAPrimaryQlClass() { result = "CharacterLiteral" }
719+
720+
/**
721+
* Gets a string which consists of the single character represented by
722+
* this literal.
723+
*
724+
* Unicode surrogate characters (U+D800 to U+DFFF) have the replacement character
725+
* U+FFFD as result instead.
726+
*/
727+
override string getValue() { result = super.getValue() }
728+
729+
/**
730+
* Gets the Unicode code point value of the character represented by
731+
* this literal. The result is the same as if the Java code had cast
732+
* the character to an `int`.
733+
*/
734+
int getCodePointValue() { result.toUnicode() = this.getValue() }
722735
}
723736

724737
/**

java/ql/lib/semmle/code/java/Type.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,10 @@ predicate erasedHaveIntersection(RefType t1, RefType t2) {
11231123
t2 = erase(_)
11241124
}
11251125

1126-
/** An integral type, which may be either a primitive or a boxed type. */
1126+
/**
1127+
* An integral type, which may be either a primitive or a boxed type.
1128+
* This includes the types `char` and `Character`.
1129+
*/
11271130
class IntegralType extends Type {
11281131
IntegralType() {
11291132
exists(string name |

java/ql/lib/semmle/code/java/frameworks/Optional.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ private class OptionalModel extends SummaryModelCsv {
77
s =
88
[
99
"java.util;Optional;false;filter;;;Element of Argument[-1];Element of ReturnValue;value",
10+
"java.util;Optional;false;filter;;;Element of Argument[-1];Parameter[0] of Argument[0];value",
11+
"java.util;Optional;false;flatMap;;;Element of Argument[-1];Parameter[0] of Argument[0];value",
12+
"java.util;Optional;false;flatMap;;;ReturnValue of Argument[0];ReturnValue;value",
1013
"java.util;Optional;false;get;;;Element of Argument[-1];ReturnValue;value",
14+
"java.util;Optional;false;ifPresent;;;Element of Argument[-1];Parameter[0] of Argument[0];value",
15+
"java.util;Optional;false;ifPresentOrElse;;;Element of Argument[-1];Parameter[0] of Argument[0];value",
16+
"java.util;Optional;false;map;;;Element of Argument[-1];Parameter[0] of Argument[0];value",
17+
"java.util;Optional;false;map;;;ReturnValue of Argument[0];Element of ReturnValue;value",
1118
"java.util;Optional;false;of;;;Argument[0];Element of ReturnValue;value",
1219
"java.util;Optional;false;ofNullable;;;Argument[0];Element of ReturnValue;value",
1320
"java.util;Optional;false;or;;;Element of Argument[-1];Element of ReturnValue;value",
21+
"java.util;Optional;false;or;;;ReturnValue of Argument[0];ReturnValue;value",
1422
"java.util;Optional;false;orElse;;;Element of Argument[-1];ReturnValue;value",
1523
"java.util;Optional;false;orElse;;;Argument[0];ReturnValue;value",
1624
"java.util;Optional;false;orElseGet;;;Element of Argument[-1];ReturnValue;value",
25+
"java.util;Optional;false;orElseGet;;;ReturnValue of Argument[0];ReturnValue;value",
1726
"java.util;Optional;false;orElseThrow;;;Element of Argument[-1];ReturnValue;value",
1827
"java.util;Optional;false;stream;;;Element of Argument[-1];Element of ReturnValue;value"
1928
]

java/ql/test/library-tests/constants/constants/Values.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void values(final int notConstant) {
1616
int binary_literal = 0b101010; //42
1717
int negative_binary_literal = -0b101010; //-42
1818
int binary_literal_underscores = 0b1_0101_0; //42
19-
char char_literal = '*'; //Not handled
19+
char char_literal = '*'; //42
2020
long long_literal = 42L; //Not handled
2121
boolean boolean_literal = true; //true
2222
Integer boxed_int = new Integer(42); //Not handled
@@ -30,7 +30,7 @@ void values(final int notConstant) {
3030
byte downcast_byte_4 = (byte) 214; // -42
3131
byte downcast_byte_5 = (byte) (-214); // 42
3232
short downcast_short = (short) 32768; // -32768
33-
int cast_of_non_constant = (int) '*'; //Not handled
33+
int cast_of_non_constant = (int) '*'; //42
3434
long cast_to_long = (long) 42; //Not handled
3535

3636
int unary_plus = +42; //42

java/ql/test/library-tests/constants/getIntValue.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| constants/Values.java:16:30:16:37 | 0b101010 | 42 |
1010
| constants/Values.java:17:39:17:47 | -... | -42 |
1111
| constants/Values.java:18:42:18:51 | 0b1_0101_0 | 42 |
12+
| constants/Values.java:19:29:19:31 | '*' | 42 |
1213
| constants/Values.java:25:20:25:27 | (...)... | 42 |
1314
| constants/Values.java:26:25:26:33 | (...)... | 42 |
1415
| constants/Values.java:27:32:27:43 | (...)... | -42 |
@@ -17,6 +18,7 @@
1718
| constants/Values.java:30:32:30:41 | (...)... | -42 |
1819
| constants/Values.java:31:32:31:44 | (...)... | 42 |
1920
| constants/Values.java:32:32:32:44 | (...)... | -32768 |
21+
| constants/Values.java:33:36:33:44 | (...)... | 42 |
2022
| constants/Values.java:36:26:36:28 | +... | 42 |
2123
| constants/Values.java:39:27:39:29 | -... | -42 |
2224
| constants/Values.java:43:27:43:28 | ~... | -1 |

java/ql/test/library-tests/literals/charLiterals/CharLiterals.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class CharLiterals {
1313
'\\',
1414
'\'',
1515
'\123', // octal escape sequence for 'S'
16+
// CodeQL uses U+FFFD for unpaired surrogates, see https://github.com/github/codeql/issues/6611
1617
'\uD800', // high surrogate
1718
'\uDC00', // low surrogate
1819
// Using Unicode escapes (which are handled during pre-processing)
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
| CharLiterals.java:5:3:5:5 | 'a' | a |
2-
| CharLiterals.java:6:3:6:10 | '\\u0061' | a |
3-
| CharLiterals.java:7:3:7:10 | '\\u0000' | \u0000 |
4-
| CharLiterals.java:8:3:8:10 | '\\uFFFF' | \uffff |
5-
| CharLiterals.java:9:3:9:10 | '\\ufFfF' | \uffff |
6-
| CharLiterals.java:10:3:10:6 | '\\0' | \u0000 |
7-
| CharLiterals.java:11:3:11:6 | '\\n' | \n |
8-
| CharLiterals.java:12:3:12:5 | '"' | " |
9-
| CharLiterals.java:13:3:13:6 | '\\\\' | \\ |
10-
| CharLiterals.java:14:3:14:6 | '\\'' | ' |
11-
| CharLiterals.java:15:3:15:8 | '\\123' | S |
12-
| CharLiterals.java:16:3:16:10 | '\\uD800' | \ufffd |
13-
| CharLiterals.java:17:3:17:10 | '\\uDC00' | \ufffd |
14-
| CharLiterals.java:19:3:19:16 | '\\u005C\\u005C' | \\ |
15-
| CharLiterals.java:20:3:20:16 | '\\u005C\\u0027' | ' |
16-
| CharLiterals.java:21:8:21:15 | 7a\\u0027 | a |
17-
| CharLiterals.java:26:4:26:6 | 'a' | a |
18-
| CharLiterals.java:27:4:27:6 | 'a' | a |
19-
| CharLiterals.java:32:3:32:5 | 'a' | a |
20-
| CharLiterals.java:32:9:32:11 | 'b' | b |
1+
| CharLiterals.java:5:3:5:5 | 'a' | a | 97 |
2+
| CharLiterals.java:6:3:6:10 | '\\u0061' | a | 97 |
3+
| CharLiterals.java:7:3:7:10 | '\\u0000' | \u0000 | 0 |
4+
| CharLiterals.java:8:3:8:10 | '\\uFFFF' | \uffff | 65535 |
5+
| CharLiterals.java:9:3:9:10 | '\\ufFfF' | \uffff | 65535 |
6+
| CharLiterals.java:10:3:10:6 | '\\0' | \u0000 | 0 |
7+
| CharLiterals.java:11:3:11:6 | '\\n' | \n | 10 |
8+
| CharLiterals.java:12:3:12:5 | '"' | " | 34 |
9+
| CharLiterals.java:13:3:13:6 | '\\\\' | \\ | 92 |
10+
| CharLiterals.java:14:3:14:6 | '\\'' | ' | 39 |
11+
| CharLiterals.java:15:3:15:8 | '\\123' | S | 83 |
12+
| CharLiterals.java:17:3:17:10 | '\\uD800' | \ufffd | 65533 |
13+
| CharLiterals.java:18:3:18:10 | '\\uDC00' | \ufffd | 65533 |
14+
| CharLiterals.java:20:3:20:16 | '\\u005C\\u005C' | \\ | 92 |
15+
| CharLiterals.java:21:3:21:16 | '\\u005C\\u0027' | ' | 39 |
16+
| CharLiterals.java:22:8:22:15 | 7a\\u0027 | a | 97 |
17+
| CharLiterals.java:27:4:27:6 | 'a' | a | 97 |
18+
| CharLiterals.java:28:4:28:6 | 'a' | a | 97 |
19+
| CharLiterals.java:33:3:33:5 | 'a' | a | 97 |
20+
| CharLiterals.java:33:9:33:11 | 'b' | b | 98 |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import semmle.code.java.Expr
22

33
from CharacterLiteral lit
4-
select lit, lit.getValue()
4+
select lit, lit.getValue(), lit.getCodePointValue()

0 commit comments

Comments
 (0)