Browse Source

Check STOMP headers against ending backslash

Issue: SPR-12418
pull/692/head
Sebastien Deleuze 10 years ago
parent
commit
18033486ae
  1. 3
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java
  2. 7
      spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/BufferingStompDecoderTests.java

3
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java

@ -260,6 +260,9 @@ public class StompDecoder {
while (index >= 0) { while (index >= 0) {
sb.append(inString.substring(pos, index)); sb.append(inString.substring(pos, index));
if((index + 1) >= inString.length()) {
throw new StompConversionException("Illegal escape sequence at index " + index + ": " + inString);
}
Character c = inString.charAt(index + 1); Character c = inString.charAt(index + 1);
if (c == 'r') { if (c == 'r') {
sb.append('\r'); sb.append('\r');

7
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/BufferingStompDecoderTests.java

@ -185,6 +185,13 @@ public class BufferingStompDecoderTests {
assertEquals(0, messages.size()); assertEquals(0, messages.size());
} }
@Test(expected = StompConversionException.class) // SPR-12418
public void endingBackslashHeaderValueCheck() throws InterruptedException {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String payload = "SEND\na:alpha\\\n\nMessage body\0";
stompDecoder.decode(toByteBuffer(payload));
}
private ByteBuffer toByteBuffer(String chunk) { private ByteBuffer toByteBuffer(String chunk) {
return ByteBuffer.wrap(chunk.getBytes(Charset.forName("UTF-8"))); return ByteBuffer.wrap(chunk.getBytes(Charset.forName("UTF-8")));

Loading…
Cancel
Save