logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sam Braam (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1069) Improper handling of JSON escape chars when deserializing JSON log events
Date Wed, 15 Jul 2015 06:17:04 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14627592#comment-14627592
] 

Sam Braam commented on LOG4J2-1069:
-----------------------------------

[BUMP]

I'd like to see this fixed in the 2.4 release so I can stop using my patched version.  Could
somebody please take a look at my patch and merge it if applicable?  It's a pretty simple
fix.

Thanks,
Sam

> Improper handling of JSON escape chars when deserializing JSON log events
> -------------------------------------------------------------------------
>
>                 Key: LOG4J2-1069
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1069
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.3
>            Reporter: Sam Braam
>            Priority: Minor
>             Fix For: 2.4
>
>
> There is an error in the handling of JSON escape characters while determining the log
event boundaries in a JSON stream.  This error is causing log events with JSON escaped characters
in the message string to be skipped.  The existing tests do not appear to cover this case,
and other serialization types are not affected.  Here is a test/fix patch: 
> {code}
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java
> index 1b81644..8ed2732 100644
> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java
> @@ -55,8 +55,10 @@ public class JsonInputStreamLogEventBridge extends InputStreamLogEventBridge
{
>          boolean inEsc = false;
>          for (int i = start; i < charArray.length; i++) {
>              final char c = charArray[i];
> -            if (!inEsc) {
> -                inEsc = false;
> +            if (inEsc) {
> +            	// Skip this char and continue
> +            	inEsc = false;
> +            } else { 
>                  switch (c) {
>                  case EVENT_START_MARKER:
>                      if (!inStr) {
> diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
> index 891e278..2bdb3c3 100644
> --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
> +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
> @@ -69,7 +69,9 @@ public abstract class AbstractSocketServerTest {
>      private static final String MESSAGE = "This is test message";
>  
>      private static final String MESSAGE_2 = "This is test message 2";
> -
> +    
> +    private static final String MESSAGE_WITH_SPECIAL_CHARS = "{This}\n[is]\"n\"a\"\r\ntrue:\n\ttest,\nmessage";
> +    
>      static final int PORT_NUM = AvailablePortFinder.getNextAvailable();
>  
>      static final String PORT = String.valueOf(PORT_NUM);
> @@ -158,6 +160,13 @@ public abstract class AbstractSocketServerTest {
>              testServer(m1, m2);
>          }
>      }
> +    
> +    
> +    @Test
> +    public void testMessagesWithSpecialChars() throws Exception {
> +        testServer(MESSAGE_WITH_SPECIAL_CHARS);
> +    }
> +    
>  
>      private void testServer(final int size) throws Exception {
>          final String[] messages = new String[size];
> {code}
> The test provided is simplistic and does not attempt to cover all possible special characters
as the bug has to do with escaped characters in general.  XML and java serialization handle
the special chars in my test string without issue - I did not attempt to locate similar cases
in the other serialization types.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message