473,420 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,420 software developers and data experts.

Security Warnings From FXCop - CA2122 & CA2123

Hi There

I am inheriting from DateTimePicker class to create a DateTimePicker
control with a configurable back colour. I got the original code from
http://dotnet.mvps.org/ then converted it to C# and it works OK in .NET
2.0 except for two warnings from CodeAnalysis:

CA2123 : Microsoft.Security : The virtual method
DateTimePicker.WndProc(Message&):Void defined by type
'System.Windows.Forms.DateTimePicker' and its override
ExtendedDateTimePicker.WndProc(Message&):Void do not have the same
LinkDemand status. Add a LinkDemand where required.

CA2122 : Microsoft.Security :
ExtendedDateTimePicker.WndProc(Message&):Void calls into
DateTimePicker.WndProc(Message&):Void which has a LinkDemand. By making
this call, DateTimePicker.WndProc(Message&):Void is indirectly exposed
to user code. Review the following call stack that might expose a way
to circumvent security protection:
->System.Windows.Forms.DateTimePicker.WndProc(Syste m.Windows.Forms.Message@)
: Void
->PickupBooking.ExtendedDateTimePicker.WndProc

My knowledge of security is amatuer and I need to deploy this project
with no security warnings ... I would greatly appreciate if anyone
could show me how fix the warnings and/or point out some good .NET 2.0
resources for security novices.

Btw, my C# 2.0 code is below.

TIA
Bill

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

namespace PickupBooking
{
public class ExtendedDateTimePicker : DateTimePicker
{
private SolidBrush m_BackBrush;

[Browsable(true),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Visible)]

public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
if (!(m_BackBrush == null))
{
m_BackBrush.Dispose();
}
base.BackColor = value;
m_BackBrush = new SolidBrush(this.BackColor);
this.Invalidate();
}
}

protected override void WndProc(ref Message m)
{
const Int32 WM_ERASEBKGND = 20;
if (m.Msg == WM_ERASEBKGND)
{
Graphics g = Graphics.FromHdc(m.WParam);
if (m_BackBrush == null)
{
m_BackBrush = new SolidBrush(this.BackColor);
}
g.FillRectangle(m_BackBrush, this.ClientRectangle);
g.Dispose();
}
else
{
base.WndProc(ref m);
}
}

protected override void Dispose(bool disposing)
{
if (disposing && !(m_BackBrush == null))
{
m_BackBrush.Dispose();
}
base.Dispose(disposing);
}
}
}

Nov 17 '05 #1
2 7958
Bill,

Kudos for running FxCop on your code. It's a good practice to engage
in.

To solve your problem, add the following attribute to your WndProc
method:

[SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.UnmanagedCode)]

This will cause a permission check to be made when the code is linked
to, to determine that the current permissions allow for unmanaged code to be
called.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<or*******@yahoo.com.au> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi There

I am inheriting from DateTimePicker class to create a DateTimePicker
control with a configurable back colour. I got the original code from
http://dotnet.mvps.org/ then converted it to C# and it works OK in .NET
2.0 except for two warnings from CodeAnalysis:

CA2123 : Microsoft.Security : The virtual method
DateTimePicker.WndProc(Message&):Void defined by type
'System.Windows.Forms.DateTimePicker' and its override
ExtendedDateTimePicker.WndProc(Message&):Void do not have the same
LinkDemand status. Add a LinkDemand where required.

CA2122 : Microsoft.Security :
ExtendedDateTimePicker.WndProc(Message&):Void calls into
DateTimePicker.WndProc(Message&):Void which has a LinkDemand. By making
this call, DateTimePicker.WndProc(Message&):Void is indirectly exposed
to user code. Review the following call stack that might expose a way
to circumvent security protection:
->System.Windows.Forms.DateTimePicker.WndProc(Syste m.Windows.Forms.Message@)
: Void
->PickupBooking.ExtendedDateTimePicker.WndProc

My knowledge of security is amatuer and I need to deploy this project
with no security warnings ... I would greatly appreciate if anyone
could show me how fix the warnings and/or point out some good .NET 2.0
resources for security novices.

Btw, my C# 2.0 code is below.

TIA
Bill

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

namespace PickupBooking
{
public class ExtendedDateTimePicker : DateTimePicker
{
private SolidBrush m_BackBrush;

[Browsable(true),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Visible)]

public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
if (!(m_BackBrush == null))
{
m_BackBrush.Dispose();
}
base.BackColor = value;
m_BackBrush = new SolidBrush(this.BackColor);
this.Invalidate();
}
}

protected override void WndProc(ref Message m)
{
const Int32 WM_ERASEBKGND = 20;
if (m.Msg == WM_ERASEBKGND)
{
Graphics g = Graphics.FromHdc(m.WParam);
if (m_BackBrush == null)
{
m_BackBrush = new SolidBrush(this.BackColor);
}
g.FillRectangle(m_BackBrush, this.ClientRectangle);
g.Dispose();
}
else
{
base.WndProc(ref m);
}
}

protected override void Dispose(bool disposing)
{
if (disposing && !(m_BackBrush == null))
{
m_BackBrush.Dispose();
}
base.Dispose(disposing);
}
}
}

Nov 17 '05 #2
Thanks Nicholas
Bill

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
I think that I start to understand this .NET security. Basically it comes to this: * You use strong names in the dll and exe, so the application user must configure this application with key...
8
by: harry | last post by:
Hi, During compilation, a C# project in my solution triggers the following warning: "warning CS0168: The variable 'ex' is declared but never used" To trigger this warning, it appears the C#...
2
by: Ralph2 | last post by:
I made some Access 2K databases using Windows98SE, now I am making some modifications and find myself inundated with Microsoft Warnings. Windows 2000 Pro and Office 2003 all updated with the latest...
5
by: Chua Wen Ching | last post by:
I had use fxcop to check my code. I had 1 confusion here. I would normally call a method by this way in my IAnimal: Example: public void CallFuncA(ushort port); But fxcop says i need to...
3
by: Chua Wen Ching | last post by:
Hi there, I had applied this security permissions in my class library based on fxcop standards. Before namespace: using System.Runtime.InteropServices; using System.Security.Permissions;
3
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
3
by: Velvet | last post by:
I ran FxCop on one of the components for my web site and the security rules what me to add " tags like the ones listed below: This breaks my ASP.NET application. So my question is,...
0
by: John Wright | last post by:
My company is trying to get a good code security checking package. I suggested FxCop but it seems to be lacking. We develop Windows Forms applications and very little asp.net applications. We...
7
by: tempest | last post by:
Hi all. This is a rather long posting but I have some questions concerning the usage of character entities in XML documents and PCI security compliance. The company I work for is using a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.