Skip to content

Commit 1268b75

Browse files
coheigeadkulp
authored andcommitted
Prevent infinite loop when a /* comment is not terminated
1 parent cff9f28 commit 1268b75

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/main/java/org/codehaus/jettison/json/JSONTokener.java

-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ public char nextClean() throws JSONException {
192192
if (next() == '/') {
193193
break;
194194
}
195-
back();
196195
}
197196
}
198197
break;

src/test/java/org/codehaus/jettison/json/JSONArrayTest.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ public void testEscapingInArrayIsTrunedOff() throws JSONException {
4343
String expectedValue = "[\"a string with / character\",{\"key\":\"http://example.com/foo\"}]";
4444
assertEquals(expectedValue, array.toString());
4545
}
46-
47-
46+
47+
public void testInfiniteLoop() {
48+
String str = "[*/*A25] **";
49+
try {
50+
new JSONArray(str);
51+
fail("Failure expected on malformed JSON");
52+
} catch (JSONException ex) {
53+
// expected
54+
}
55+
}
56+
57+
public void testInfiniteLoop2() {
58+
String str = "[/";
59+
try {
60+
new JSONArray(str);
61+
fail("Failure expected on malformed JSON");
62+
} catch (JSONException ex) {
63+
// expected
64+
}
65+
}
4866
}

0 commit comments

Comments
 (0)