On Wed, 1 Dec 2004 14:28:20 -0800
"Mark Pizzolato" <[EMAIL PROTECTED]> wrote:

> I'm trying to use clamd via TCP Stream connections to ClamAV under
> cygwin, but under any concurrent load, clamd was logging:
> 
>                ERROR: ScanStream: Can't create temporary file.
> 
> I tracked this down to clamd/scanner.c's use of tmpfile() which is 
> documented as being NOT a threadsafe API.  As it turns out, tmpfile()

That was rather caused by a w32 limitation of tmpfile() and not its
thread safeness. Boguslaw Brandys described the problem here, IIRC.

> is actually threadsafe iff the local implementation of getpid()
> returns a different value for each execution thread (i.e. as it does
> on Linux). Hence, most environments don't see this issue.

Every normal POSIX compliant platform provides reentrant and thread safe
tmpfile().

All tmpfile() calls will be removed in the future, though. We want
libclamav to use a single temporary directory that could be changed
dynamically with cl_settmpdir()

> While exploring the issue of threadsafety in ClamAV, I dug deeper into
> the other places where temp files are created and used in libclamav. 
> I found numerous places where concurrency issues existed, even though

Theoretical races will always be possible, that's why cli_gentemp uses
a cryptographic function to generate temporary names. I don't see real
advantages of your changes.

> memory/open file leaks, possible invalid memory references).  There
> was also logic in scanners.c which attempted to use mutex to limit
> concurrency  while scan rar files (to avoid issues with using
> tmpfile()).  This logic would serialize RAR checking, but some of the

The mutex is used to protect non-reentrant unrarlib call and not
tmpfile().

> progress which would return success instead.  The need for this mutex
> logic has been eliminated.

This change makes libclamav thread unsafe. 

-- 
   oo    .....         Tomasz Kojm <[EMAIL PROTECTED]>
  (\/)\.........         http://www.ClamAV.net/gpg/tkojm.gpg
     \..........._         0DCA5A08407D5288279DB43454822DC8985A444B
       //\   /\              Thu Dec  2 00:33:37 CET 2004

Attachment: pgpnnuPDNzJO6.pgp
Description: PGP signature

_______________________________________________
http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel

Reply via email to