On Mon, 14 Mar 2005 11:14:32 -0500 (EST) "Calin A. Culianu" <[EMAIL PROTECTED]> wrote:
> Hi guys, > > This is my fourth submission for an environment variable patch for > VirusEvents. The other 3 I submitted all had various bugs. > > This patch makes the virusaction function reentrant (my previous > patches broke reentrancy). > > It didn't occur to me initially that modifying the environment is > incompatible with reentrancy. As such, virusaction() needs to fork > before calling putenv() and then calling system() (which itself > forks, of course). > > Please accept this patch, and use it to replace all my other previous > patches.. thanks!! > > PS: Could you kindly advise on whether this patch is rejected or > accepted? Thanks.. I've looked at your patch and it's definitely too complicated. Moreover it's not portable (free_env_var - although it _should_ work on most systems) as the old UNIX rule says: "_never_ free variable passed to putenv()". Please remove all the constructions like: +#define ENV_PREFIX "CLAM_VIRUSEVENT_" +#define ENV_FILENAME (ENV_PREFIX "FILENAME") +#define ENV_VIRUSNAME (ENV_PREFIX "VIRUSNAME") +enum env_var { FILENAME = 0, VIRUSNAME, N_ENV_VARS }; +struct env_var_desc { + const char * name; + int namelen; +}; + +static const struct env_var_desc env_vars[] = { + /* Array is indexed using enum env_var above.. */ + { ENV_FILENAME, strlen(ENV_FILENAME) }, + { ENV_VIRUSNAME, strlen(ENV_VIRUSNAME) } +}; [...] + if (var < 0 || var >= N_ENV_VARS) return NULL; + if (!value) value = ""; + desc = &env_vars[var]; + len = desc->namelen + strlen(value) + sizeof(char)*2; + buf = (char *) mcalloc(len, sizeof(char)); + snprintf(buf, len, "%s=%s", desc->name, value); [...] and replace it with a simple code like this: #define ENV_VIRUS "CLAM_VIRUSEVENT_VIRUSNAME" #define ENV_FILE "CLAM_VIRUSEVENT_FILE" pt = (char *) mmalloc(strlen(ENV_VIRUS) + strlen(virusname) + 2); sprintf(pt, "%s=%s", ENV_VIRUS, virusname); putenv(pt); pt = (char *) mmalloc(strlen(ENV_FILE) + strlen(filename) + 2); sprintf(pt, "%s=%s", ENV_FILE, filename); putenv(pt); and of course do not free pt (but you already know it). -- oo ..... Tomasz Kojm <[EMAIL PROTECTED]> (\/)\......... http://www.ClamAV.net/gpg/tkojm.gpg \..........._ 0DCA5A08407D5288279DB43454822DC8985A444B //\ /\ Fri Mar 18 16:11:18 CET 2005
pgpGfGz3Ecj7l.pgp
Description: PGP signature
_______________________________________________ http://lurker.clamav.net/list/clamav-devel.html