Skip to content

Commit

Permalink
Prevent infinite loop when a /* comment is not terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
coheigea authored and dkulp committed Sep 22, 2022
1 parent cff9f28 commit 1268b75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/codehaus/jettison/json/JSONTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ public char nextClean() throws JSONException {
if (next() == '/') {
break;
}
back();
}
}
break;
Expand Down
22 changes: 20 additions & 2 deletions src/test/java/org/codehaus/jettison/json/JSONArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ public void testEscapingInArrayIsTrunedOff() throws JSONException {
String expectedValue = "[\"a string with / character\",{\"key\":\"http://example.com/foo\"}]";
assertEquals(expectedValue, array.toString());
}



public void testInfiniteLoop() {
String str = "[*/*A25] **";
try {
new JSONArray(str);
fail("Failure expected on malformed JSON");
} catch (JSONException ex) {
// expected
}
}

public void testInfiniteLoop2() {
String str = "[/";
try {
new JSONArray(str);
fail("Failure expected on malformed JSON");
} catch (JSONException ex) {
// expected
}
}
}

0 comments on commit 1268b75

Please sign in to comment.