<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Calling VariantClear on a OUT param can lead to security hole !!!</title><link>http://blogs.msdn.com/jaiprakash/archive/2007/01/15/calling-variantclear-on-a-out-param-can-lead-to-security-hole.aspx</link><description>There was a mail thread going on internally where a security hole was suspected due to VarianltClear() being called inside a method on a out param. Since i am new to COM world, I asked my fellow MSFTian Paul Dempsey that how can it be possible. Here is</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Calling VariantClear on a OUT param can lead to security hole !!!</title><link>http://blogs.msdn.com/jaiprakash/archive/2007/01/15/calling-variantclear-on-a-out-param-can-lead-to-security-hole.aspx#9525524</link><pubDate>Wed, 01 Apr 2009 10:00:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9525524</guid><dc:creator>pweerd</dc:creator><description>&lt;p&gt;Hi Jaiprakash,&lt;/p&gt;
&lt;p&gt;I'm not sure if this is right. I had the same feeling about it and programmed my COM-object in that way. But it is leaking memory when called from VBScript. There is not much documentation about who is responsible for freeing VARIANTS in COM.&lt;/p&gt;
&lt;p&gt;Many people are using VARIANTs by always initializing and always cleaining them.&lt;/p&gt;
&lt;p&gt;My COM object declared the following method:&lt;/p&gt;
&lt;p&gt;HRESULT Test ([out]VARIANT *Value);&lt;/p&gt;
&lt;p&gt;and in them implementation I did fill it with a string, without calling VariantClear().&lt;/p&gt;
&lt;p&gt;VBScript code:&lt;/p&gt;
&lt;p&gt;dim i, obj, v&lt;/p&gt;
&lt;p&gt;set obj = CreateObject (&amp;quot;myobject&amp;quot;)&lt;/p&gt;
&lt;p&gt;for i=0 to 1000000&lt;/p&gt;
&lt;p&gt; &amp;nbsp; obj.Test v&lt;/p&gt;
&lt;p&gt;next&lt;/p&gt;
&lt;p&gt;v was correctly filled, but it is leaking fast.&lt;/p&gt;
&lt;p&gt;This behaviour is different when you change the attribute from [out] into [out,retval]. After that its not leaking any more. The VBScript code is than:&lt;/p&gt;
&lt;p&gt;dim i, obj, v&lt;/p&gt;
&lt;p&gt;set obj = CreateObject (&amp;quot;myobject&amp;quot;)&lt;/p&gt;
&lt;p&gt;for i=0 to 1000000&lt;/p&gt;
&lt;p&gt; &amp;nbsp;v = &amp;nbsp;obj.Test&lt;/p&gt;
&lt;p&gt;next&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Peter vd Weerd&lt;/p&gt;
</description></item></channel></rss>