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

Thomas Wolf commented on SSHD-1209:
-----------------------------------

I suppose it works this way because of 
[https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-13#section-3.1]
 : "Data sent on stderr by the server SHOULD be considered free format debug or 
supplemental error information".

The original code sent an SSH encoded string (length, text bytes), so the 
client got (SSH_MSG_CHANNEL_EXTENDED_DATA, channelId, SSH_EXTENDED_DATA_STDERR, 
length of data, data=(length, text bytes)). Apparently "free form" means one is 
supposed to send just (SSH_MSG_CHANNEL_EXTENDED_DATA, channelId, 
SSH_EXTENDED_DATA_STDERR, length of data, data=text bytes).

This also explains the extra characters. "SFTP User Exit error: 
stat.throwExcpetion was set to true" is 58 characters (and bytes, since it's 
7-bit ASCII). With buffer.putString(), this is prefixed by the length, so it 
sends the bytes 0x00 0x00 0x00 0x3A and the the text bytes. ASCII code 0x3A 
(decimal 58) is ":".

Same for "Utils.java from admin File name should be syncsort.txt Only": that's 
60 characters, and ASCII code 60 is "<".

"free form" doesn't say it had to be text, though. RFC 4254 defines 
SSH_EXTENDED_DATA_STDERR for "stderr data", and stderr is typically assumed to 
be text, but that's it. It doesn't say what line separator is used, if it's 
text, nor what character encoding would be used.

 

> Write to error stream for custom exception is appending a extra word at the 
> beginning
> -------------------------------------------------------------------------------------
>
>                 Key: SSHD-1209
>                 URL: https://issues.apache.org/jira/browse/SSHD-1209
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 2.7.0
>            Reporter: Susmit Sarkar
>            Priority: Major
>         Attachments: image-2021-08-19-12-50-01-922.png, 
> image-2022-01-18-14-19-31-614.png, image-2022-01-18-14-23-38-696.png
>
>
> Hello Team,
>  
> We have a class as below
>  
> {code:java}
> DetailedSftpErrorStatusDataHandler implements SftpErrorStatusDataHandler, 
> ChannelSessionAware, DetailedSftpErrorStatusDataHandler implements 
> SftpErrorStatusDataHandler, ChannelSessionAware, 
> AsyncCommandErrorStreamAware, CommandDirectErrorStreamAware {
> {code}
> and we have overridden the :
>  
> resolveErrorMessage and setIoErrorStream(IoOutputStream errStream) 
> {code:java}
>  @Override
>  public void setIoErrorStream(IoOutputStream errStream) { 
>      this.errStream = errStream;
>  }
> {code}
> finally we are writing to the error stream:
> {code:java}
> private void writeMsgToErrorStream(String refinedUserExitMessage) {
>     ByteArrayBuffer buf = new ByteArrayBuffer();
>     buf.putString(refinedUserExitMessage + 
> System.getProperty("line.separator")); 
>     try { if (errStream != null) { 
>         errStream.writeBuffer(buf); 
>           }
>     } catch (Exception e) { 
>     }
>  }
> {code}
> Once the data is written to error stream we are gettig proper message to the 
> console:
> !image-2021-08-19-12-50-01-922.png!
> But there is an extra charater getting appended at the first character *<* 
> Utils.java ....
> I have no idea from where this *<* is coming from, and that changes with the 
> first character like if it is P it would be *>, when starting with S it gets 
> appended with Z*
> Any help will be appreciated.
> Thanks,
> Susmit
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to