![]() |
![]() |
|
February 10, 2004FxCop: How the Cop beat me down - A ReviewOk, so I have been talking about FxCop for a while, and during all my trails I really liked the tests it performed. Today I thought I would put FxCop 1.23 through our master sources of a product we are about to release. OMG. Lets just say my C style of writing is not appreciated by the FxCop rules. At the start this morning, I had 588 violations reported by FxCop. Not a pretty sight. But then I started reading their "Rules Details" to understand why it was flagged. I am really impressed with the detail of the rules. In most cases I found the "Additional Information" quite useful, although I will admit the documentation does more to show examples on how to actually resolve the issues. A majority of the violations failed in a single rule library. As I marshal a LOT of C style structs to P/Invoke native Win32 components as part of my kernelmode compatibility stuff, I guess this should be expected. I found that around 40% - 50% were errors because I would use underlines and capital letters (ie: SECURITY_DESCRIPTOR) which FxCop didn't like. I know I could name it to be more .NET friendly, but I like keeping the consistancy for the structs across the C# and C boundaries of my master sources tree. As such, I "excluded" quite a bit of violations to pass the test. These weren't actually false-positives... they were right. I just believe my style is more right for my needs. I could have simply turned off that rule check completely... but it did find some internal structs which I could and did change. Something for you to consider: It is better NOT to supress a complete test. Don't be lazy.... analyze every violation and make an informed decision. I personally liked how you could attach a note to each violation you would exclude, allowing other developers to udnerstand WHY I excluded the violation from the tests. FxCop found two security violations in my code which were focused on the fact I was using a virtual override to WndProc for two forms without setting the LinkDemand. I didn't even know WndProc had a Demand set to it... so it was good to see that FxCop caught it. I spent a great deal of time reviewing this in an attempt to figure out the LinkDemand status of the Control.WndProc... only to have someone point out to me an example where it sets the Demand state, which means I just had to add "[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]" to pass the test. The rest of the violations I simply went and fixed. Most were .NET style issues which I am still trying to master/accept (ie:using a property instead of a method) and a lot of localization issues with CultureInfo/IFormatProvider. After 2 and a half hours, all tests passed. 588 violations were reduced to 0... with about 200 in the exclude list. I will take some time to think about the impact of the naming conventions, and then go tackle the exclude list at a later date. Some things really should be renamed, but are left in so they match the C code in the kernel. (Example... .NET doesn't like a function name of OpenFIFOQue. I can pass that test if I change it to OpenFifoQue. Not a major change, but left in for clarity for anyone who is grepping through the sources to match up code against either side of the kernel) Now, with such a great tool I did find some things I think could be improved upon. Most of it has to do with the user interface. There may be work arounds for many of this, I just don't know about them yet:
All and all I found FxCop a great tool to use. When I have some time I think I will learn how to write my own security rules, and then put them into FxCop for testing on a regualr basis. If I can figure out how to automate FxCop during postbuild events... I will even make it a daily build task. Thanks to the FxCop team for their great work. Nice tool. Posted by SilverStr at February 10, 2004 12:15 PM | TrackBackComments
I don't get why a tool cares about your naming conventions. In what way are they important? A naming convention is just that, a convention, it won't make your code better or worse, as long as you stick to whatever convention you like. And anyway why are Microsoft trying to decide on a correct naming convention anyway, we are talking about the company that brought us Hungarian Notation. And from what stereo (mutual acquaintance of Dana’s and myself) it requires _variable as a way to name member variables, which is disgusting. Programs like FXCop should concentrate on things that are relevant to the quality of the code. You say yourself that you now have some code that you changed to follow the FXCop convention, and some that you kept with your old C style, so in fact you have gone from one consistent style to a mix of two inconsistent styles, surely that is a regression? In you free time, give pclint a try. Yes it also has a mode to search for Hungarian Notation, but that is easily disable-able Microsoft are trying to decide on correct naming conventions *because* we brought you Hungarian Notation and we're making up for it ;). Actually, it is a big deal because the amount of managed APIs we're shipping with Longhorn and Whidbey is significant and consistency in naming and usage is hugely important across such a large surface area. Dana BTW we have an FxCop t-shirt for you for your useful comments, pls email me w/instructions on where to ship it. Thanks - Michael Posted by: Michael Murray at February 23, 2004 03:48 PM |
![]() ![]()
My 5 Favorite Books
Writing Secure Code
Secure Programming Cookbook Security Engineering Secure Coding Principles & Practice Inside the Security Mind ![]()
My 5 Favorite Papers
Smashing the Stack
Penetration Studies Covert Channel Analysis of Trusted Systems DoD Trusted Computer System Evaluation Criteria NSA Security Recommendation Guides ![]()
Archives
December 2005
November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 February 2005 January 2005 December 2004 November 2004 October 2004 September 2004 August 2004 July 2004 June 2004 May 2004 April 2004 March 2004 February 2004 January 2004 December 2003 November 2003 October 2003 September 2003 August 2003 July 2003 June 2003 May 2003 April 2003 March 2003 February 2003 January 2003 December 2002 November 2002 October 2002 September 2002 August 2002 July 2002 ![]() |
|