Content deleted Content added
wording |
|||
Line 1:
Defensive programming is a form of [[defensive design]] intended to ensure the continuing function of a piece of software in spite of unforeseeable usage of
Here are some hints on '''defensive programming techniques''' to avoid creating security problems.
Many of these techniques also improve general quality of code, because almost any major bug can be potentially used by a [[cracker (computing)|cracker]] for a [[Denial of Service]] or other attack.
Note that the techniques below are ''not'' sufficient to ensure security: see the articles [[computer insecurity]] and [[secure computing]] for more information.
Line 11 ⟶ 10:
<!-- Please expand this article. These random notes should be changed to a more coherent article. -->
* One of the most common problems is unchecked use of constant-size structures and functions for dynamic-size data (the [[buffer overflow]] problem). This is especially common for [[string]] data in [[C programming language|C]]. C library functions like <tt>gets</tt> and <tt>scanf</tt> should never be used since the maximum size of the input buffer is not passed as an argument.
* Never make
* Either leave
▲* Never make your code more complex than necessary. Complexity breeds bugs, including security problems.
▲* Either leave your code available to everyone on the Net (see [[Free software]] or [[open source definition]]) or hire someone who will do [[security audit]] for you.
* If possible, reuse code instead of writing from scratch.
* Encrypt all important data which flow the Net.
* All data is important until proved otherwise.
* All code is unsecure until proven otherwise.
* Never make
*If
Crackers are likely to invent new kinds of incorrect data. For example, if
you checked if a requested file is not "/etc/passwd", a cracker might pass another
Line 26 ⟶ 24:
----
Preconditions, Postconditions and Invariants validation are also part of Defensive Programming. This may involve checking
Within functions, you may want to double check that you
Generally speaking then, it is preferrable to throw intelligible exception messages that enforce part of your API contract and guide the client programmer instead of returning values that a client programmer is likely to be unprepared for and hence minimize their complaints and increase robustness and security of your software.
|