15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Secure Computing 641<br />

start. The idea is that if programmers focus on security when designing a<br />

program, they won’t have to waste time patching up their programs later.<br />

The first type of security involves examining the code of a program to<br />

remove any flaws. The most common type of flaw involves code that works<br />

but can be manipulated to cause an unexpected result. A common example<br />

of this type of problem is a buffer overflow.<br />

A buffer overflow occurs when a program expects data that fits a certain<br />

size, such as accepting up to ten characters <strong>for</strong> a password. If you feed the<br />

computer data that’s larger than expected, such as a 12-character password,<br />

the program should just ignore these extra 2 characters. However, a computer<br />

might accidentally store these extra two characters in its memory.<br />

Normally such excess data would be harmless, but sometimes this excess<br />

data gets stored in a part of memory that contains other data that the computer<br />

uses, such as a list of tasks the computer will follow next. By flooding<br />

the computer with excess data, a hacker can literally change the computer’s<br />

behavior.<br />

One way to exploit this flaw is to shove excessive data to flood the computer’s<br />

memory and then tack on an extra set of commands <strong>for</strong> the computer<br />

to follow. This tacked-on command then gets buried in the computer’s<br />

memory, which causes the computer to follow those instructions.<br />

Oftentimes, those instructions tell the computer to weaken its defenses,<br />

such as opening a hole in the firewall to let the hacker into the computer.<br />

To prevent problems, such as buffer overflows, programmers need to sift<br />

through their code and make sure that their code handles unexpected data<br />

correctly rather than just dumping it anywhere in memory. Examining code<br />

can be tedious, so programmers often use special testing tools that can spot<br />

such problems automatically.<br />

Book VII<br />

Chapter 3<br />

Computer Security<br />

Buffer overflow problems are especially common in programs written in C<br />

and C++. That’s why more programmers are flocking to newer languages, like<br />

C# and Java, because these languages prevent buffer overflows, which can<br />

result in more secure and reliable software.<br />

Security by design<br />

Most security patches close common flaws in programs, but just removing<br />

these flaws is like locking a screen door to keep out intruders. A more proactive<br />

solution is to design security into a program from the beginning, which is like<br />

getting rid of a screen door and replacing it with a solid metal door instead.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!