Skip to content

Commit

Permalink
Allow tid = 0 for SMB1 (#63)
Browse files Browse the repository at this point in the history
Proper invalid/reserved TID for SMB1 is 0xFFFF not 0.
  • Loading branch information
mbechler committed Apr 8, 2018
1 parent e23afcd commit b785373
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/main/java/jcifs/internal/TreeConnectResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ public interface TreeConnectResponse extends CommonServerMessageBlockResponse {
*/
boolean isShareDfs ();


/**
* @return whether the tree id is a valid one
*/
boolean isValidTid ();

}
5 changes: 3 additions & 2 deletions src/main/java/jcifs/internal/smb1/ServerMessageBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public abstract class ServerMessageBlock implements CommonServerMessageBlockRequ
*/

private byte command, flags;
protected int headerStart, length, batchLevel, errorCode, flags2, tid, pid, uid, mid, wordCount, byteCount;
protected int headerStart, length, batchLevel, errorCode, flags2, pid, uid, mid, wordCount, byteCount;
protected int tid = 0xFFFF;
private boolean useUnicode, forceUnicode, extendedSecurity;
private volatile boolean received;
private int signSeq;
Expand Down Expand Up @@ -984,7 +985,7 @@ public void reset () {
this.received = false;
this.digest = null;
this.uid = 0;
this.tid = 0;
this.tid = 0xFFFF;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ public final boolean isShareDfs () {
}


/**
* {@inheritDoc}
*
* @see jcifs.internal.TreeConnectResponse#isValidTid()
*/
@Override
public boolean isValidTid () {
return getTid() != 0xFFFF;
}


@Override
protected int writeParameterWordsWireFormat ( byte[] dst, int dstIndex ) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ public final int getTid () {
}


@Override
public boolean isValidTid () {
return getTreeId() != 0;
}


/**
* {@inheritDoc}
*
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/jcifs/smb/SmbTreeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,10 @@ else if ( transport.isSMB2() ) {
* @throws IOException
*/
private void treeConnected ( SmbTransportImpl transport, SmbSessionImpl sess, TreeConnectResponse response ) throws CIFSException {
int treeId = response.getTid();
if ( treeId == 0 ) {
throw new SmbException("TreeID is NULL");
if ( !response.isValidTid() ) {
throw new SmbException("TreeID is invalid");
}
this.tid = treeId;
this.tid = response.getTid();
String rsvc = response.getService();
if ( rsvc == null && !transport.isSMB2() ) {
throw new SmbException("Service is NULL");
Expand Down

0 comments on commit b785373

Please sign in to comment.