RSS 2.0 Feed
2004-05 Entries
摘要:上一篇随笔将“缓冲区溢出”翻译成“Buffer Overflow”,但是在微软程序员必读书Writing Secure Code 书写安全代码(2nd Edition)之中,“缓冲区溢出”是翻译成“Buffer Overrun”的。我个人的理解是两者有着相同的意思。 从google上搜索这2个术语,结果"Buffer Overflow"有859,000个搜索结果而"Buffer Overrun"只有116,000。有趣的是,当将搜索限制在www.microsoft.com的site上,Buffer overrun的使用频度是buffer overflow的2倍。 为了和来自微软的资料一致,我将在以后的随笔中使用buffer overrun. 贴子以"现状"提供且没有任何担保也没有授予任何权利。...[阅读全文]

posted @ | Feedback (13) | Filed Under [ 安全|security ]

摘要:可经验证(Verifiable)的托管(managed)代码是不会出现缓冲区溢出的问题的。但是在下列情况下,仍然要防止Buffer Overflow: Unsafe C#; COM Interop; Platform Invokes (P/Invoke); 使用不可验证(Unverifiable)的语言,如Managed C++. 举个例子,下面这个private函数完全可能造成Buffer Overflow,调用它的函数必须防止这个问题。private unsafe static void PrivateCopyUnguarded(byte[] src, int srcIndex, byte[] dest, int destIndex, int length){  fixed(byte* srcPointer = src, destPointer = dest)  {      byte* srcPosition = srcPointer + srcIndex;    byte* destPosition = destPointer + destIndex;    while (length-- > 0)   {      *destPosition++ = *srcPosition++;    }  } } 下面是调用InternalCopyUnguarded的public方法:public static void MemoryCopy(byte[] src, int srcIndex,  byte[] dest, int destIndex, int length){  if ((length < 0) || (srcIndex < 0) || (destIndex < 0) || (srcIndex + length > src.Length) || (destIndex + length > dest.Length))   {    throwErrorException();  }  PrivateCopyUnguarded(src, srcIndex, dest, destIndex, length);}可是:MemoryCopy的实现有问题么?敬请评论。 贴子以"现状"提供且没有任何担保也没有授予任何权利。...[阅读全文]

posted @ | Feedback (13) | Filed Under [ 安全|security ]

摘要:本周.NET Quiz为单项选择题。正确解答需要对.NET有较深入的掌握。第一到第四组按从容易到难排列,当然难易对每个人都是不同的。 第一组: C#2.0增加的语言性能不包括:(1)Generics (2)Iterators (3) My Namespace (4) Partial Types 第二组:myLable是System.Windows.Forms.Labell的一个实例(即Label myLabel = new Label();),表达式(myLabel.CanFocus || myLabel.CanSelect)的值为(1) true (2) false (3)true或者false,取决于其他条件  (4) 编译错误 第三组:以下来自V1.0的Framwork Library的命名符合微软Design Guideline的是(1)CLSCompliantAttribute (2)HttpSessionState.SessionID (3)Color.FromArgb  (4)System.MarshalByRefObject 第四组: 在ASP.NET 1.0和1.1中,HttpSessionState.SessionID的长度为(1) 20 (2)24 (3)30 (4)从20到30随机长度,包括20但不包括30。 贴子以"现状"提供且没有任何担保也没有授予任何权利。...[阅读全文]

posted @ | Feedback (41) | Filed Under [ Quiz ]

摘要:重粒子评论道:希望增加一些关于安全性的随笔。You wish for it, and you get it. 看下面这个代码,其中 _position, _length等都是private field. _mem包括了用户感兴趣的信息。每一次调用ReadByte, 或者因为错误条件而得到Exception, 或者如愿得到下一个值,或者在_position已经超过总_length的情况下得到-1. 仅从Race Conditon的角度去看,当有2个或者多个线程(thread)使用该函数时,会再什么情况下出问题? public unsafe int ReadByte() {    if (!_hasInternalError)  {    throwErrorException();  }  if (_position >= _length)  {    return -1;   }  return _mem[_position++]; } 这个代码的主要问题就在_position++上。如果几个thread都通过了_position >= _length的检查而连续调用_mem[_position++]就有可能访问到超出_length的地址空间。因为没有对每个Thread都可以改变的_position提供保护,就会造成Race Condition. 如何避免这个问题?可以使用一个新的局部变量pos来保存_position的值。如下: public unsafe int ReadByte() {    if (!_hasInternalError)  {    throwErrorException();  }  int pos = _position;   if (pos >= _length)  {    return -1;   }  _position = pos + 1;  return _mem[pos]; } 别的方法,如lock, 和重粒子刚刚评论的[MethodImplAttribute(MethodImplOptions.Synchronized)]也是可以避免Race Condition,但是代价会比上面的解法大。 贴子以"现状"提供且没有任何担保也没有授予任何权利。...[阅读全文]

posted @ | Feedback (21) | Filed Under [ 安全|security ]

摘要:从使用ContainerControl.ActiveControl的讨论之中,应该注意到一个控件的CanFocus和CanSelect可以是不同的。Label这样的Control,虽然CanSelect为False,其CanFocus确是可以为True的. CanFocus: in order for a control to receive input focus, the control must have a handle assigned to it, and the Visible and Enabled properties must both be set to true. CanSelect: This property returns true if the control has ControlStyles.Selectable set to true, is contained in another control, and all its parent controls are both visible and enabled....[阅读全文]

posted @ | Feedback (6) | Filed Under [ WinForm ]

摘要:据最新报道,Yahoo预计在几个小时内推出新版Toolbar的beta,其最新功能就是可以扫描硬盘发现Spyware.这对普通用户而言是个好消息。 其技术是基于Pest Patrol的软件。家庭用户买这个公司的软件需要40美元,现在可以免费使用了。 在MSN, Google和Yahoo的Toolbar激烈竞争下,广大消费者有了更多的选择。现在连Anti-Spyware都有了,下一步会增加什么? 新闻来自ZDNet. ...[阅读全文]

posted @ | Feedback (2) | Filed Under [ IT ]

摘要:Visual Studio.NET 2005 CTP(Community Technology Preview )的2004年5月版本已经发布了。我现在正在一台XPSP2的机器上安装。简短笔记如下: .NET Framework版本为v2.0.40426; 对应VS05版本8.0.40426.16; 安装好Framework之后,需要重新启动机器。如果启动后安装失败,再试一次; VS.NET安装好之后,需要重新启动机器,然后可以安装MSDN; 首次包括Visual Studio Team System; 2004年夏天将会推出VS05 Beta,但是不包括Visual Studio Team System(其beta将在年底前发布); 此次安装未必能彻底卸除,需安装在可以重装操作系统的机器上; 2005年3月1日过期。 问答题:40426这个版本号的意义会是什么呢? 贴子以"现状"提供且没有任何担保也没有授予任何权利。...[阅读全文]

posted @ | Feedback (16) | Filed Under [ Visual Studio ]