Skip to content

Commit

Permalink
Add exceptional cases for error response parsing
Browse files Browse the repository at this point in the history
https://msdn.microsoft.com/en-us/library/cc246722.aspx lists
several cases in which an error status does not indicate
an error response message but must be treated as a regular one.
  • Loading branch information
mbechler committed Aug 5, 2018
1 parent 90e1696 commit ac7be69
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/main/java/jcifs/internal/smb2/io/Smb2ReadResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import jcifs.internal.smb2.ServerMessageBlock2Response;
import jcifs.internal.smb2.Smb2Constants;
import jcifs.internal.util.SMBUtil;
import jcifs.smb.NtStatus;


/**
Expand Down Expand Up @@ -115,4 +116,15 @@ else if ( structureSize != 17 ) {
return bufferIndex - start;
}

/**
* {@inheritDoc}
*
* @see jcifs.internal.smb2.ServerMessageBlock2#isErrorResponseStatus()
*/
@Override
protected boolean isErrorResponseStatus () {
return getStatus() != NtStatus.NT_STATUS_BUFFER_OVERFLOW && super.isErrorResponseStatus();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public Smb2IoctlRequest ( Configuration config, int controlCode, byte[] fileId,

@Override
protected Smb2IoctlResponse createResponse ( CIFSContext tc, ServerMessageBlock2Request<Smb2IoctlResponse> req ) {
return new Smb2IoctlResponse(tc.getConfig(), this.outputBuffer);
return new Smb2IoctlResponse(tc.getConfig(), this.outputBuffer, this.controlCode);
}


Expand Down
25 changes: 22 additions & 3 deletions src/main/java/jcifs/internal/smb2/ioctl/Smb2IoctlResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Smb2IoctlResponse extends ServerMessageBlock2Response {
/**
* @param config
*/
public Smb2IoctlResponse ( Configuration config ) {
public Smb2IoctlResponse ( Configuration config) {
super(config);
this.outputBuffer = null;
}
Expand All @@ -61,7 +61,17 @@ public Smb2IoctlResponse ( Configuration config, byte[] outputBuffer ) {
this.outputBuffer = outputBuffer;
}


/**
* @param config
* @param outputBuffer
* @param ctlCode
*/
public Smb2IoctlResponse ( Configuration config, byte[] outputBuffer, int ctlCode ) {
super(config);
this.outputBuffer = outputBuffer;
this.ctlCode = ctlCode;
}

/**
* @return the ctlCode
*/
Expand Down Expand Up @@ -128,7 +138,16 @@ protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
*/
@Override
protected boolean isErrorResponseStatus () {
return getStatus() != NtStatus.NT_STATUS_INVALID_PARAMETER && super.isErrorResponseStatus();
int status = getStatus();
return status != NtStatus.NT_STATUS_INVALID_PARAMETER &&
!( status == NtStatus.NT_STATUS_INVALID_PARAMETER &&
( ctlCode == Smb2IoctlRequest.FSCTL_SRV_COPYCHUNK ||
ctlCode == Smb2IoctlRequest.FSCTL_SRV_COPYCHUNK_WRITE ) ) &&
!( status == NtStatus.NT_STATUS_BUFFER_OVERFLOW &&
( ctlCode == Smb2IoctlRequest.FSCTL_PIPE_TRANSCEIVE ||
ctlCode == Smb2IoctlRequest.FSCTL_PIPE_PEEK ||
ctlCode == Smb2IoctlRequest.FSCTL_DFS_GET_REFERRALS ) ) &&
super.isErrorResponseStatus();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jcifs.internal.smb1.trans.nt.FileNotifyInformationImpl;
import jcifs.internal.smb2.ServerMessageBlock2Response;
import jcifs.internal.util.SMBUtil;
import jcifs.smb.NtStatus;


/**
Expand Down Expand Up @@ -107,4 +108,15 @@ public List<FileNotifyInformation> getNotifyInformation () {
return this.notifyInformation;
}

/**
* {@inheritDoc}
*
* @see jcifs.internal.smb2.ServerMessageBlock2#isErrorResponseStatus()
*/
@Override
protected boolean isErrorResponseStatus () {
return getStatus() != NtStatus.NT_STATUS_NOTIFY_ENUM_DIR && super.isErrorResponseStatus();
}


}

0 comments on commit ac7be69

Please sign in to comment.