• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    針對軟件測試開發技術 .NET 框架的安全編碼指南

    發布: 2009-8-17 10:54 | 作者: 不詳 | 來源: 領測軟件測試網 | 查看: 83次 | 進入軟件測試論壇討論

    領測軟件測試網

    以下 C# 代碼示例顯示了如何使用引用來修改裝箱的值類型。

    using System; using System.Reflection; using System.Reflection.Emit; using System.Threading; using System.Collections; class bug { // Suppose you have an API element that exposes a // field through a property with only a get accessor. public object m_Property; public Object Property { get { return m_Property;} set {m_Property = value;} // (if applicable) } // You can modify the value of this by doing // the byref method with this signature. public static void m1( ref int j ) { j = Int32.MaxValue; } public static void m2( ref ArrayList j ) { j = new ArrayList(); } public static void Main(String[] args) { Console.WriteLine( "http:////// doing this with value type" ); { bug b = new bug(); b.m_Property = 4; Object[] objArr = new Object[]{b.Property}; Console.WriteLine( b.m_Property ); typeof(bug).GetMethod( "m1" ).Invoke( null, objArr ); // Note that the property changed. Console.WriteLine( b.m_Property ); Console.WriteLine( objArr[0] ); } Console.WriteLine( "http:////// doing this with a normal type" ); { bug b = new bug(); ArrayList al = new ArrayList(); al.Add("elem"); b.m_Property = al; Object[] objArr = new Object[]{b.Property}; Console.WriteLine( ((ArrayList)(b.m_Property)).Count ); typeof(bug).GetMethod( "m2" ).Invoke( null, objArr ); // Note that the property does not change. Console.WriteLine( ((ArrayList)(b.m_Property)).Count ); Console.WriteLine( ((ArrayList)(objArr[0])).Count ); } } }   確保方法訪問的安全

    某些方法可能不適合由不受信任的任意代碼調用它們。此類方法會導致幾個風險:方法可能會提供某些受限制信息;可能會相信傳遞給它的任何信息;可能不會對參數進行錯誤檢查;或者,如果參數錯誤,可能會出現故障或執行某些有害操作。您應當注意這些情況,并采取適當的操作來確保方法的安全。

    在某些情況下,您可能需要限制不打算公開使用、但仍必須是公共的方法。例如,您可能有一個需要在自己的 DLL 之間進行調用的接口,因此它必須是公共的,但您不想公開它,以防止用戶使用它或防止惡意代碼利用它作為入口點進入到您的組件中。對不打算公共使用(但仍必須是公共)的方法進行限制的另一個常見理由是,避免用文檔記錄和支持非常內部的接口。

    托管代碼為限制方法訪問提供了幾個方式:

    將可訪問性的作用域限制到類、程序集或派生類(如果它們是可信任的)。這是限制方法訪問的最簡單方式。請注意,通常派生類的可信賴度比它們派生自的類更低,但在某些情況下,它們可以共享超類標識。特別是,不要從關鍵字 protected 推斷信任情況,因為在安全上下文中,該關鍵字不是必須使用的。

    將方法訪問限制到指定標識(實質上,是您選擇的任何特殊證據)的調用方。

    將方法訪問限制到擁有您所選權限的調用方。

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>