📄 implementation
字号:
This document details a few steps and decisions taken to ensure vsftpd is freeof common implementation flaws.Tackling the buffer overflow============================Probably the most common implementation flaw causing security problems is thebuffer overflow. Buffer overflows come in many shapes and sizes - overflowsonto the stack, overflows off the end of dynamically malloc()'ed areas,overflows into static data areas. They range from easy to spot (where a usercan put an arbitrary length string into a fixed size buffer), to verydifficult to spot - buffer size miscalculations or single byte overflows. Orconvoluted code where the buffer's definition and various usages are farapart.The problem is that people insist on replicating buffer size handling codeand buffer size security checks many times (or, of course, they omit sizechecks altogther). It is little surprise, then, that sometimes errors creepin to the checks.The correct solution is to hide the buffer handling code behind an API. Allbuffer allocating, copying, size calculations, extending, etc. are done bya single piece of generic code. The size security checks need to be writtenonce. You can concentrate on getting this one instance of code correct.From the client's point of view, they are no longer dealing with a buffer. Thebuffer is encapsulated within the buffer API. All modifications to the buffersafely go through the API. If this sounds familiar, it is because what vsftpdimplements is very similar to a C++ string class. You can do OO programmingin C too, you know ;-)A key point of having the buffer API in place is that it is MORE DIFFICULT toabuse the API than it is to use it properly. Try and create a buffer memorycorruption or overflow scenario using just the buffer API.Unfortunately, secure string/buffer usage through a common API has not caughton much, despite the benefits it brings. Is it under publicised as a solution?Or do people have too much sentimental attachment to strcpy(), strlen(),malloc(), strcat() etc? Of notable exception, it is my understanding that atleast the rather secure qmail program uses secure buffer handling, and I'dexpect that to extend to all Dan Bernstein software. (Let me know of other goodexamples).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -