Quote usernames in the sshd_log if necessary
If the incoming username contains a space it would throw off any
program reading the log file. Instead quote the value so that a
parser could detect the quoted entry and recover.
Change-Id: If74e8c1f6820df9ba9369b039e6285fefff62549
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshLog.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshLog.java
index d50d4dd..9c75e24 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshLog.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshLog.java
@@ -308,7 +308,12 @@
Object val = event.getMDC(key);
buf.append(' ');
if (val != null) {
- buf.append(val);
+ String s = val.toString();
+ if (0 <= s.indexOf(' ')) {
+ buf.append(QuotedString.BOURNE.quote(s));
+ } else {
+ buf.append(val);
+ }
} else {
buf.append('-');
}