[jcifs] Potential concurrency problem
Ronny Schuetz
Usenet.r96 at gishpuppy.com
Tue Sep 30 10:56:13 GMT 2008
Hi,
jCIFS version is 1.2.19. Just ran into an ArrayIndexOutOfBoundsException
in NbtAddress#getWINSAddress(). NbtAddress#NBNS contains 4 entries, Java
failed to access index 4.
The only reason why the index was incremented to 4 is - as it looks like
- that NbtAddress#switchWINS() (at least the part incrementing
nbnsIndex) isn't synchronized, i.e. it could happen that it gets
incremented to a value outside the array bounds if executed by multiple
threads in parallel.
This can be verified by using multiple threads calling
UniAddress#getByName() in loops in parallel (with
jcifs.netbios.cachePolicy set to 0 and all netbios timeouts set 1 to
enforce the switching) and replacing the line (NbtAddress#switchWINS()):
nbnsIndex = (nbnsIndex + 1) < NBNS.length ? nbnsIndex + 1 : 0;
by equivalent code that includes some sleeps at the right place
if((nbnsIndex + 1) < NBNS.length)
{
try { Thread.sleep(1000); } catch(InterruptedException e) {}
nbnsIndex = nbnsIndex + 1;
}
else
{
try { Thread.sleep(1000); } catch(InterruptedException e) {}
nbnsIndex = 0;
}
Synchronizing the method NbtAddress#switchWINS() in general or just the
line changing the index on the class object seems to help.
Best regards,
Ronny
More information about the jcifs
mailing list