允许用户在输入字段输入无限量的信息,会给他们进行缓冲区溢出的攻击造成机会,这会导致应用程序崩溃或者允许他们(未经授权就)获得计算机的控制权。
将接受社会安全号的字段设置为最大11个字符(包括连字符)是如何限制用户输入的一个例子:
'Set the length on the control to prevent the user
from entering
'too many characters.
txtSSNum.MaxLength = 11
'or validate the length of the value
If Len(txtSSNum.Text) > 11 Then
'Do not process
End If
将长度检测应用到所有可能的输入处是很重要的。命令行的参数、用户输入的控制信息、组件里公共方法的参数等等,都是需要进行检查的地方。