BharatBhasha.com
 
Free Articles  >>  Technology >>  Page 10  >> 

5 Security Considerations When Coding

1. Input Checking

Always check user input to be sure that it is what you expected. Make sure it doesn’t contain characters or other data which may be treated in a special way by your program or any programs called by your program.
This often involves checking for characters such as quotes, and checking for unusual input characters such as non-alphanumeric characters where a text string is expected. Often, these are a sign of an attack of some kind being attempted.

2.Range Checking

Always check the ranges when copying data, allocating memory or performing any operation which could potentially overflow. Some programming languages provide range-checked container access (such as the std::vector::at() in C++, but many programmers insist on using the unchecked array index [] notation. In addition, the use of functions such as strcpy() should be avoided in preference to strncpy(), which allows you to specify the maximum number of characters to copy. Similar versions of functions such as snprintf() as opposed to sprintf() and fgets() instead of gets() provide equivalent length-of-buffer specification. The use of such functions throughout your code should prevent buffer overflows. Even if your character string originates within the program, and you think you can get away with strcpy() because you know the length of the string, that doesn’t mean to say that you, or someone else, won’t change things in the future and allow the string to be specified in a configuration file, on the command-line, or from direct user input. Getting into the habit of range-checking everything should prevent a large number of security vulnerabilities in your software.

3.Principle Of Least Privileges

This is especially important if your program runs as root for any part of its runtime. Where possible, a program should drop any privileges it doesn’t need, and use the higher privileges for only those operations which require them. An example of this is the Postfix mailserver, which has a modular design allowing parts which require root privileges to be run distinctly from parts which do not. This form of privilege separation reduces the number of attack paths which lead to root privileges, and increases the security of the entire system because those few paths that remain can be analysed critically for security problems.

4.Don’t Race

A race condition is a situation where a program performs an operation in several steps, and an attacker has the chance to catch it between steps and alter the system state. An example would be a program which checks file permissions, then opens the file. Between the permission check the stat() call and the file open the fopen() call an attacker could change the file being opened by renaming another file to the original files name. In order to prevent this, fopen() the file first, and then use fstat(), which takes a file descriptor instead of a filename. Since a file descriptor always points to the file that was opened with fopen(), even if the filename is subsequently changed, the fstat() call will be guaranteed to be checking the permissions of the same file. Many other race conditions exist, and there are often ways to prevent them by carefully choosing the order of execution of certain functions.

5.Register Error Handlers

Many languages support the concept of a function which can be called when an error is detected, or the more flexible concept of exceptions. Make use of these to catch unexpected conditions and return to a safe point in the code, instead of blindly progressing in the hope that the user input won’t crash the program, or worse!


Article Source: http://www.BharatBhasha.com
Article Url: http://www.bharatbhasha.com/technology.php/42258


Article Added on Monday, May 8, 2006
Other Articles related to "5 Security Considerations When Coding" by Bryce Whitty

•Sending Passwords By Email
It amazes me how many sites allow you to register, and then send you an e-mail to your registered address containing your password in plain-text. There is never a warning stating that the site will email the password you use, for all to see. Sending passwords by e-mail works when you forget a password. The site changes it and e-mails you the new one, which you then use to log in and change it to something else. The e-mailed password is not active for very long, and it isn’t something you...

•Public Key SSH Login
SSH is a popular system allowing a remote shell (command interpreter) to be used over a secure connection. By secure, here, I mean that the connection is encrypted, authenticated and integrity checked. The encryption prevents attackers reading the contents of the data being transmitted, the authentication allows both the client and the server to be sure that they are connected to the other, and not to some intermediate system in a man-in-the-middle attack, and the integrity checking ensures...

•Google Friend or Foe
Don’t get me wrong, almost all of us love Google to death. It has single-handedly changed the direction of this entire industry to something that is accessible for everyone. However, while Google is the darling poster child of Wall Street and the general public, there lurks a danger of abuse. We will cover this in a bit, but first let’s look at a few years ago when the World Wide Web was still a novel concept. We had a handful of methods of finding information. They were so-called search...

Articles In LimeLight
  • What To Look For In A Good Sleep Clinic
    By Gary M. Miller Added on Saturday, April 19, 2008
  • SEO For Number One Rankings
    By Daniel Millions Added on Wednesday, April 30, 2008
  • Professional vs. DIY Duct Cleaning
    By Amy Nutt Added on Thursday, May 15, 2008
  • Men Love Competition
    By Ron Petracek Added on Thursday, May 1, 2008
  • Three Feng Shui Bedroom Tips
    By MalcyM Added on Friday, May 16, 2008
  • A Dictionary Of Horse Racing Terms - P
    By Mike Davies Added on Friday, May 16, 2008
  • Sydney Singles Scene
    By Mark Date Added on Thursday, May 15, 2008
  • Save On Home Improvement
    By Jim Ames Added on Monday, April 21, 2008
  • A Nursery Full Of Roses
    By Hilary Templeton Added on Friday, May 16, 2008
  • Get A Baby Gift Set That Will Make Mom Smile
    By Mandie Klein Added on Wednesday, May 14, 2008
  • What Every Woman Must Know About Football And Marriage
    By Myla Madson Added on Wednesday, April 30, 2008
  • What's So Great About SEO?
    By Derek Rogers Added on Saturday, May 3, 2008
  • The Role Of Weather On Horse Racing Tips
    By Delrick Mckay Added on Wednesday, May 14, 2008
  • Pharmacopoeia The Complete Medical Guide
    By Daniel Millions Added on Wednesday, May 14, 2008
  • Life Coach Or Life Hoax?
    By Anthony Kouma Added on Friday, May 16, 2008
  • Save Money On Relocating
    By Pat Doyle Added on Tuesday, May 13, 2008
  • How To Take Adorable Photos Of Your Pet
    By Carey Paris Added on Wednesday, April 30, 2008
  • Loan Payment Protection Is A Great Unknown
    By Simon Burgess Added on Saturday, April 19, 2008
  • Starbucks Corporate Culture - Early Adopters
    By Eric Prince Added on Thursday, May 15, 2008
  • The Evolution Of The Credit Scorecard
    By Sam Miller Added on Wednesday, May 14, 2008
  • About Author Bryce Whitty :

    Bryce Whitty owns and runs <a target="_blank" href="http://www.technibble.com">computer repair website called <a target="_blank" href="http://www.technibble.com">Technibble.com. A website that provides technical how-to’s for repairing your computer. Technibble also has many guides for getting into the <a target="_blank" href="http://www.technibble.com">computer business or managing your existing one. We also cover other side topics such as Security and Software.

    Publishers / Webmasters
    Tell A Friend
    Comments / Questions?
    Download this article in PDF
    Search through all the articles:


    272 Users Online!
    Related Articles:
    Latest Articles:
     
    Technology >> Top 50 Articles on Technology >> All Articles in this category
    Category - >
    • Advertising • Advice • Affiliate Programs • Automobiles
    • Be Your Own Mentor • Careers • Communication • Consumers
    • CopyWriting • Crime • Domain Names • DoT com Entrepreneur Corner
    • Ebooks • Ecommerce • Education • Email
    • Entertainment • Environment • Family • Finance And Business
    • Food & Drink • Gardening • Health & Fitness • Hobbies
    • Home Business • Home Improvement • Humour • House Holds
    • Internet And Computers • Kiddos and Teens • Legal Matters • Mail Order
    • Management • Marketing • Marriage • MetaPhysical
    • Motivational • MultiMedia • Multi Level Marketing • NewsLetters
    • Pets • Psychology • Religion • Parenting
    • Politics • Sales • Science • Search Engine Optimization
    • Site Promotion • Sports • Technology • Travel
    • Web Development • Web Hosting • WeightLoss • Women's Corner
    • Writing • Miscellaneous Articles • Real Estate • Arts And Crafts


    Disclaimer: The information presented and opinions expressed in the articles are those of the authors
    and do not necessarily represent the views of Bharatbhasha.com and/or its owners.


    Copyright © AwareINDIA. All rights reserved || Privacy Policy || Terms Of Use || Author Guidelines || Article Search
    FAQs Link To Us || Submit An Article || All Products || Free Downloads|| Contact Us || Site Map  || Advertise with Us ||
    Click here for Special webhosting packages for visitors of this website only!