Slashdot Mirror


How Do You Know Your Code is Secure?

bvc writes "Marucs Ranum notes that 'It's really hard to tell the difference between a program that works and one that just appears to work.' He explains that he just recently found a buffer overflow in Firewall Toolkit (FWTK), code that he wrote back in 1994. How do you go about making sure your code is secure? Especially if you have to write in a language like C or C++?"

349 comments

  1. You don't by CockMonster · · Score: 5, Funny

    Just get others to formally review it so if anything is found, there's collective responsibilty

    1. Re:You don't by Anonymous Coward · · Score: 2, Funny
      Prophylactic: A preventive measure. The word comes from the Greek for "an advance guard," an apt term for a measure taken to fend off a disease or another unwanted consequence.


      Sorry CockMonster, with today's DNA testing, getting others to participate in your virgin sacrifice wouldn't save you if you had a buffer overflow.

      *Warning* as appropriate as prophylactic might seem under its definition for use in the computer industry when talking about firewalls, sandboxes, etc, please keep in mind that some female is probably going to holler sexual harassment when they hear it. Just as they would if you mentioned their stack overflow.
    2. Re:You don't by jorgevillalobos · · Score: 4, Insightful

      Modded as funny? This is as real as it gets. At least in the private sector.

    3. Re:You don't by hackstraw · · Score: 2, Insightful

      Just get others to formally review it so if anything is found, there's collective responsibilty

      Yes, that is funny, but there is truth to it as well (which is why its funny).

      Security, software development, and everything else is a process, not an event. It gets better over time, and basically, the way that issues come out is for them to be found "in the wild". And as these issues are found, better tools and techniques make the process better over time, but I don't envision a world where people just think of bugfree, usable, featureful software that just appears, but all in all it keeps getting better.

      The error in question:while(lp != (struct listelem *)0) {
                      free(lp);
                      lp = lp->next;
              }
      is pretty silly, and I don't know how it took over a decade to find that. In my experience, code like that crashes pretty regularly, and debugging it will point to the error.

      Today, what some programmers do is to do FREE(lp); where FREE() is a macro or something that does if (a) { free(a); a=NULL; }. This prevents double frees, and ensures that future use of the pointer will predictably die with a null pointer exception. In 2006, bugs like this should not find themselves in C code. We now check our stuff, use languates or tools that check for crap like this for us, or whatever. In 1994, I guess it was OK for such a bug to be interoduced into code, but not in 2006.

    4. Re:You don't by Poltras · · Score: 1
      uh you know that your code doesn't work no more, right? I'd mod you as funny, but I don't know if you're serious.

      while(lp) {
      struct listelem *next = lp->next;
      free(lp);
      lp = next;
      }
      What is more, your solution to the problem is futile in this case because we already know that lp is not null, otherwise it would have left the while loop, and if you set lp to null, you cannot take the next element to it (well you can because of deferred freeing, or just that the memory is not yet reallocated, but it's a BAD THING). Come on, linked list 101. And the error is quite classic back in 1996. Detecting it is not as easy as you put since the program can run without segmentation fault in normal environment.
    5. Re:You don't by Anonymous Coward · · Score: 2, Informative

      The purpose of his macro isn't to fix the dangling reference problem. The purpose is to help developers find dangling reference problems in their code.

    6. Re:You don't by jgrahn · · Score: 1
      Today, what some programmers do is to do FREE(lp); where FREE() is a macro or something that does if (a) { free(a); a=NULL; }. This prevents double frees, and ensures that future use of the pointer will predictably die with a null pointer exception.

      Yeah, right. How often do you think a is the only reference to that memory in the program? If you do have a problem, it's likely to be in some completely different part of the code, where there's an alias for a, with a completely different lifetime. Nothing you can do to a will change that.

      (And really, what's the if(a) part all about? free(3) has accepted NULL pointers for the last twenty years or so.)

    7. Re:You don't by nuzak · · Score: 1

      > please keep in mind that some female is probably going to holler sexual harassment when they hear it

      See, if a guy raises his eyebrows at the word, that's okay, but those hysterical females just can't take it, so if she reacts to the word, get your lawyers ready.

      Is that the gist?

      --
      Done with slashdot, done with nerds, getting a life.
    8. Re:You don't by zacronos · · Score: 1

      if you set lp to null, you cannot take the next element to it

      That was the point. This GP's macro solution would have worked for the code given in GP's post, because FREE(lp) would set lp to null, and then trying to access the next element would have caused the program to crash from dereferencing a null pointer. Upon debugging, the author would have found the problem and fixed it.

    9. Re:You don't by Anonymous Coward · · Score: 0
      See, if a guy raises his eyebrows at the word, that's okay, but those hysterical females just can't take it, so if she reacts to the word, get your lawyers ready.

      Is that the gist?


      No, but it only takes one female to misunderstand or get $$ in her eyes or have desires to get rid of the person using the word. A male could also stir up trouble here but wouldn't have as many corporate policies or federal and state regulations to support him, unless of course he bases his arguement on it offending females. The *warning* was just for additional humor, the afforementioned understated truths are what makes the humor work and I somewhat expected someone to take exception to the female part but didn't want to block any "no women here" jokes that might follow by using co-worker instead. I have known a lot of women that would apply such a term themselves and pick on other women for complaining about men using them.

      DRM is by definition a prophylactic, but who wants to listen to their music or watch a movie with a condom over their head?
    10. Re:You don't by Poltras · · Score: 1

      Yes, as stated by the informative AC just above you. I didn't see it like this; the parent was stating that it was a solution.

    11. Re:You don't by tepples · · Score: 1

      free(3) has accepted NULL pointers for the last twenty years or so.

      MSVCRT does not conform to the C standard.

  2. Verified by Anonymous Coward · · Score: 5, Funny

    I get mine verified by microsoft

    1. Re:Verified by Anonymous Coward · · Score: 2, Informative

      On one hand your comment is funny due to the chronic security risks associated with MS products.

      On the other hand, MS has some of the best code analysis technology available in Prefast, FXCop, SAL, and Application Verifier:

      http://msdn.microsoft.com/msdnmag/issues/05/11/SDL /default.aspx

      Disclaimer from the linked content:

      "Security tools will not make your software secure. They will help, but tools alone do not make code resilient to attack. There is simply no replacement for having a knowledgeable work force that will use the tools to enforce policy."

  3. Secure? by nahime · · Score: 2, Insightful

    Secure?? What does it mean?

    1. Re:Secure? by Anonymous Coward · · Score: 0

      Hey pardner... I reckon you need someone to sec ure dick?

    2. Re:Secure? by Anonymous Coward · · Score: 0

      Breaker breaker 1-9er, this is RedTip, can I get a bj check?? Yiiiiiii-Haaaauuuugghhh!

  4. Shovel method by dangitman · · Score: 4, Funny

    I hit it with a shovel. If the code doesn't fall apart, I know it's pretty securely attached to my computer. If not, I add more epoxy glue.

    --
    ... and then they built the supercollider.
    1. Re:Shovel method by UnknowingFool · · Score: 1

      After I hit mine with I shovel, I buried it in the desert in a secret location. To help me remember the location I made maps, but not just one main map. I tattooed different pieces of the map onto the backs of the child slave labor that I employed to move it to the desert. Then I scattered the children all over the world.

      --
      Well, there's spam egg sausage and spam, that's not got much spam in it.
    2. Re:Shovel method by Nappa48 · · Score: 1

      Sounds like some film based on ancient Egypt and "the gods".

  5. Don't use C++ as if it was only "C with classes" by quigonn · · Score: 4, Insightful

    Modern C++ provides a very nice and functional Standard Library which provides a lot of functionality and data structures such as strings, vectors, lists, maps, sets. While using these available classes does not completely rule out making programming mistakes related to buffer overflows and such, it at least minimizes the risk of producing stupid buffer overflow through badly done string handling. At least that's what my experience is.

    Actually, the best thing would be not to use C or C++ at all, but that's where reality comes into play. Most developers don't even have the choice which language they should use, but that is predetermined by the employer and/or supervisor.

    --
    A monkey is doing the real work for me.
  6. Avoid direct memory access by Ed+Avis · · Score: 4, Insightful

    You introduce buffer overflows when you deal with buffers directly. In conventional C with its standard library you're encouraged to do this rather a lot, for example many of the string functions expect you to allocate a char buffer of big enough size and pass it in. The language's arrays are just syntactic sugar for accessing raw memory, with no bounds checks.

    However you don't have to do it like this, especially not in C++ which has a safe string class (for example) as part of its standard library. Unfortunately C++'s vector type still doesn't do bounds checking with the usual [] dereferencing - you have to call the at() method if you want to be safe. But the general principle is: don't do memory management yourself, use some higher-level library (which exist for C too) and let someone else do the memory management for you.

    You can write a C++ program and be pretty confident it doesn't have buffer overruns simply because it doesn't use pointers or fixed-size buffers, but relies on the resizable standard library containers.

    --
    -- Ed Avis ed@membled.com
    1. Re:Avoid direct memory access by peterpi · · Score: 1
    2. Re:Avoid direct memory access by ojQj · · Score: 5, Informative

      Unfortunately stl isn't binary compatible. That means you have to make sure you've compiled with exactly the same version of the stl with all the components of your program which accept and pass strings. This in turn makes it impossible to release different parts of your program separately from each other if you are using the stl at the interface between your components.

      There are a couple of solutions to this problem:

      1.) Pass character arrays at the interfaces between your components and immediately put those character arrays under the control of your library once they come in.
      2.) Write or find your own string library and pass that string class between program components. Be careful when doing this. Mistakes will come back to byte you.

      All of it's kind of nasty. It'd be nice if C++ could standardize their binary representation, even if it's only a standard valid per platform.

      Then there's also:

      3.) Choose a language which unlike C++ already has a standardized binary representation for strings, or a system global interpreter for a varying binary representation. This is just an extension of the "higher-level library which does the memory management for you" option really.

      Don't get me wrong -- I'm agreeing with the parent post. I'm just adding a caveat.

    3. Re:Avoid direct memory access by Viol8 · · Score: 4, Insightful

      "simply because it doesn't use pointers "

      Err, how much C++ have you written? I've yet to see any complex C++ *without* pointers since you cant reference or use dynamically created objects using the new operator without them. Not to mention in 101 other instances where they're useful.

    4. Re:Avoid direct memory access by Jeff+DeMaagd · · Score: 1

      I think there's a qualifier that needs to be added here. A C++ program is safe if you use standard C++ coding methods, the classes that you are using are safe and don't have to write your own classes. Having the STL classes helps a lot here but there may be situations where one might want an alternative data storage class which might require the coder to do memory management.

    5. Re:Avoid direct memory access by Anonymous Coward · · Score: 0

      boost::shared_ptr is your friend :)

    6. Re:Avoid direct memory access by Anonymous Coward · · Score: 0

      It'd be nice if C++ could standardize their binary representation, even if it's only a standard valid per platform.

      Yes. They could call it cross vendor C++ ABI or something.

    7. Re:Avoid direct memory access by ZorbaTHut · · Score: 1

      I've seen, and written, a lot of complex C++ that didn't use pointers directly. I try to avoid pointers in general - any case where I use pointers is carefully hidden behind abstraction.

      (This doesn't count pointers-as-function-parameters, as long as they're not stored anywhere. I use those pretty often. But I've found that generally stored pointers are just plain difficult to deal with properly, unless ownership and invalidation semantics are utterly 100% clear, and even then they're tough.)

      --
      Breaking Into the Industry - A development log about starting a game studio.
    8. Re:Avoid direct memory access by ojQj · · Score: 1

      It's certainly very useful to enforce rules about your vtables and etc. It's actually a pre-requisite for ever getting to the problem with the strings. The ABI for Windows is COM; there your binary string representation is BSTR. BSTRs can be manipulated using various libraries, they are however not explicitly associated with the STL or any other library, much less a library which is part of the C++ standard. So you can pick a library, or you can do your memory management, avoid buffer-runs and etc yourself.

      That would be option 1 above.

    9. Re:Avoid direct memory access by Anonymous Coward · · Score: 0

      Yes. Of course all of this really comes to the C++ standards comity needing to grow a pair and define some form of first-class string data type so we can drop std::string and define it properly as part of the ABI (They may have done already. I havn't bothered to follow the latest C++ standard)

    10. Re:Avoid direct memory access by Anonymous Coward · · Score: 1, Insightful

      Unfortunately stl isn't binary compatible. That means you have to make sure you've compiled with exactly the same version of the stl with all the components of your program which accept and pass strings. This in turn makes it impossible to release different parts of your program separately from each other if you are using the stl at the interface between your components.

      There are a couple of solutions to this problem: Actually, I can think of one more:

      3.) Don't use different versions of the C++ standard library* in the first place.

      *It's not called STL. That was the original name of a container library developed at HP that was later included in the C++ ISO spec. It also never even included a string class.
    11. Re:Avoid direct memory access by rucs_hack · · Score: 5, Insightful

      I code predominasntly in C, and I find very few problems with allocating my own string buffers and so on. Doing your own memory allocation/deallocation does not instantly mean you have a program full of buffer overflows and security holes, although many people seem to assume this is the case.

      What does that is rushed code, poor design and inadequate testing. These feature heavily in the vast majority of commercially produced code I've seen. Frankly most of what I've seen is horrifically bad. With code of such low quality, C should be avoided, but that's not C's fault, it's crap house coding rules. C is elegent, minimal, and mindbendingly fast. This does not mark it as ideal for enterprise tools, but it does have a place there, for time intensive operations.

      It is extremely easy to ensure buffers in C have a strictly limited inputs, and do not encounter overflows. It's also easy to not do this, and thus faster. That I suspect, is where most of the problems come from.

      Open source code used in the enterprise seems nowadays to be starting to suffer from similer problems to the commercial code I've seen, although commenting schemes are better. The problem seems to me to be a feeling that things must be pushed forward to compete. That isn't a good plan. Slower development, more testing before actual deployment, and less feature creep are what is needed.

    12. Re:Avoid direct memory access by Anonymous Coward · · Score: 0
    13. Re:Avoid direct memory access by Anonymous Coward · · Score: 0

      Indeed, specially if we have in mind that any C++ coder must use pointers in order to do polymorphism in C++.

    14. Re:Avoid direct memory access by Drathus · · Score: 1

      I wish I had mod points right now.

      I agree with everything you've said. The "problems" that most people like to toss around with C/C++ are not the fault of the language, but the programmer.

    15. Re:Avoid direct memory access by JebusIsLord · · Score: 1

      But that's like saying "look, there isn't a problem with guns, its with gun owners." Lets just accept the fact that people are morons, and give them the tools to minimize the damage they can do (ie Java - bad coders will write slow clunky code rather than exploity code).

      --
      Jeremy
    16. Re:Avoid direct memory access by mrsbrisby · · Score: 1
      I've seen, and written, a lot of complex C++ that didn't use pointers directly. I try to avoid pointers in general - any case where I use pointers is carefully hidden behind abstraction.
      I hate asking, but why are you using C++ if you use a level of indirection that makes it almost as slow as Java (gcj)?

      I'm of the opinion that there's nothing inherently wrong with pointers and that really the whole world went to shit the moment people started trusting that code actually does what the comments say it does.

      Therefore I say comments are bad for security as it _discourages_ review, instead of encouraging it.
    17. Re:Avoid direct memory access by Curien · · Score: 1

      You do it that same way you write Java code "without pointers". You use higher-level abstractions to hide (and prevent errors in) the implementation details.

      Programming in C++ requires restraint.

      --
      It's always a long day... 86400 doesn't fit into a short.
    18. Re:Avoid direct memory access by just_another_sean · · Score: 1

      Mistakes will come back to byte you.

      Comments like this are why I love /. ! :-)

      --
      Creationist Textbook Stickers Declared Unconstitutional by CowboyNeal
    19. Re:Avoid direct memory access by ZorbaTHut · · Score: 1

      What makes you think indirection involves a speed hit? If it's not a virtual function, it's nearly free, and it only gets really bad if you start making virtual functions that do very little work.

      Do you avoid functions in your code?

      Abstraction doesn't require virtual functions, remember. A simple class, or even a set of functions labeled "use these functions", is a level of abstraction. OpenGL, for example, is a perfectly functional abstraction barrier without necessarily involving a single virtual function call. (It could, in theory, be inlined entirely, if you had a software OpenGL.)

      I agree that there's nothing inherently wrong with pointers, and I do in fact use them when I think it's worth the hassle. But they are moderately errorprone and you do have to be very careful with them. I feel they're better avoided as much as possible unless you have an extremely good reason to use them. (These do exist.)

      --
      Breaking Into the Industry - A development log about starting a game studio.
    20. Re:Avoid direct memory access by Viol8 · · Score: 1

      Using higher level abstractions doesn't get rid of the pointers , it just covers them up. They're still there in the lower level code. Whereas in java there is no concept of a pointer to start with. Anyway , you don't always want to hide pointers , they exist for a good reason.

    21. Re:Avoid direct memory access by Drathus · · Score: 1

      They have those tools (Java, etc)

      The problem with your comment is not all people are morons. If we reduce the available tools and languages to account for the lowest common denominator then we deserve the crap which would be created.

      Those who can safely and productively create code in languages like C and C++ should be encouraged to continue to do so. Don't blame the tool, blame the user.

      And yes, it isn't a problem with guns; It's entirely with people who use them.

    22. Re:Avoid direct memory access by AuMatar · · Score: 2, Insightful

      I prefer to just fire the bad coders. Really, memory management is pretty fucking simple. You request a resource, you use it, you release it. CS is full of this sequence.

      *Using a file
      *Using a semaphore
      *Using a database connection
      *Any other resource that is unique

      If you can't get this simple concept, you shouldn't be programming. Ever.

      The only difficulty is if you have ownership of pointers bouning all over. Of course, I've never seen a good design that did that. Good modular design solves the ownership problem for you in 99.9% of cases. In fact, if I ever find a place in code where it isn't clear, its a warning to me that I need to redesign that part of the codebase.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    23. Re:Avoid direct memory access by Gazzonyx · · Score: 1

      Just a thought, and please correct me if I'm wrong, but with C the problem isn't the char *myString;.
      Rather, the problem is that in the underlying code you're probably playing with myString as type void * in order to fit it in a generic function call or method. I think malloc() will handle the call, provided that you actually call malloc(), and check that it doesn't return null .
      However, many of us (myself more guilty than most) just take for granted that the memory we need exists. We also usually don't bother to check stuff like isalpha(), etc... Just my $.02.

      --

      If I mod you up, it doesn't necessarily mean I agree with what you've said, sorry.

    24. Re:Avoid direct memory access by iabervon · · Score: 1

      Testing doesn't really help much. The cases you're worried about are the ones which aren't going to happen in 12 years of actual use, and which are only triggered by specially-constructed input. If you knew how to test in order to trigger the bug, you could just look at the code and see if the bug is there.

      The main thing is really good design, good style, and unrushed review. One important thing is to do all of the tricky pointer-fiddling in a file of utility routines, so that it only has to be right once. Another is to get the compiler to report all your typos (e.g., there's a brilliant C trick with macros for getting the compiler to typecheck arguments in template-like ways before casting this information away and calling a function who correctness depends on things matching). Then, run it through valgrind and fix all of your uninitialized values, off-by-one errors, and memory leaks.

    25. Re:Avoid direct memory access by rucs_hack · · Score: 1

      I do make heavy use of the Richard Stallman Auto Criticizer, aka splint. That's a very good tool for finding potential problems, although it is a tad strict

    26. Re:Avoid direct memory access by Ed+Avis · · Score: 1

      I meant to say 'pointer arithmetic', but I agree with ZorbaTHut that by using value types, standard library containers, references and the occasional shared_ptr or smart_ptr, you don't need to use raw pointers (or new and delete) very much.

      --
      -- Ed Avis ed@membled.com
    27. Re:Avoid direct memory access by arkanes · · Score: 1
      You're going to provide a link to your credentials and all the proof you have that all the C code you've ever written is secure, right? I've never heard anyone who's well known as a C author, especially someone who's known for working on secure code, to say anything like this.

      Buffer overflows are found in C code every day, even in heavily audited C code. Written by extremely skilled programmers. It *is* a fault of the language, and it's stupid to argue otherwise - it's mindless fanboyism at best. It can only be worked around by an extreme (and, as shown by real world code, unachievable) level of discipline and expertise, coupled with fallible automatic tools.

      People write in C for lots of reasons. Nobody who isn't a cretin writes in it because they think it's innately secure.

    28. Re:Avoid direct memory access by Jerry+Coffin · · Score: 1
      Indeed, specially if we have in mind that any C++ coder must use pointers in order to do polymorphism in C++.

      I know I've been away from comp.std.c++ for a while, but I still thought I would have noticed if they were removing references from the language!

      --
      The universe is a figment of its own imagination.
    29. Re:Avoid direct memory access by Anonymous Coward · · Score: 0

      http://www.hpl.hp.com/techreports/95/HPL-95-11.pdf That's the original STL report. No "string" type is mentioned. "string" is part of the C++ ISO spec. :) It just happened to be modeled after the other sequence types in the STL.

    30. Re:Avoid direct memory access by Anonymous Coward · · Score: 0

      > Really, memory management is pretty fucking simple. You request a resource, you use it, you release it.

      Golly, you're a freakin genius. It's all about 1's and 0's. I mean jeez, how hard is it to just get two simple numbers?

    31. Re:Avoid direct memory access by tricorn · · Score: 1

      I agree pretty much with the post you're responding to. When I say "testing", I mean that I test all the boundary conditions of each individual subroutine in the library I'm writing to make sure it works with all specified conditions, detects all errors it is supposed to detect, and that any limitations are well documented. In some cases where error checking is too expensive to do in production, I also include a debugging facility, either dynamic or compile-time, to do more extensive input checking. This can also be used in checking code that calls the routine, to verify that it is passing things correctly. Once I have the core routines finished and tested, I then rely heavily on them.

      I find that a lot of programming that is done in C++ really should have been done in straight C. It isn't really using any "object oriented" techniques, it's just doing straight linear programming, wrapped in a more complex description, usually doing lots of things the programmer doesn't understand, often much more inefficiently than they expect. With C, you really only have to worry about a few things, and if you're manic about being paranoid about those things, you really won't have a problem: a) opening a file, it might fail, always check it; b) allocating or re-allocating memory, it might fail, always check it; c) stale pointers, zero the thing if there's any doubt that it might be used again, if there can be multiple persistent pointers to a block of memory, have the discipline to keep track of those pointers so you don't free the memory prematurely; d) buffer overflows, whether on the stack or the heap; bounds check if there's ANY doubt whatsoever, document what the bounds are and where the limits come from, etc.

      More complex programming, e.g. multi-threading, requires similar discipline - always check that when you create a thread, it succeeded (I had a program where the OS would balk at creating too many new threads too quickly, I had to add in a yield() and re-try a few times before returning an error); creating a mutex or condition variable and initializing it, always check the error results; setting thread priority, always check the error results.

      More complex is how to handle "impossible" errors; exceptions in C++ is one of the best reasons to go beyond straight C for this issue. Usually, the best choice is to log the error and kill the entire process, and have a higher layer to restart the program if it is critical. I've found that most such issues occur during initialization, where the best choice IS to have it be a fatal error, but designing the response to various potential errors (socket closed unexpectedly, failed to open a file, invalid input) is important to do early on so you can have a unified approach to such errors and ensure you don't have resource leaks when things don't terminate as expected. C++ and Java allow some of this to be done easier than in C, but it still isn't that hard to do even in straight C, but only if you think about it ahead of time!

    32. Re:Avoid direct memory access by tepples · · Score: 1

      I hate asking, but why are you using C++ if you use a level of indirection that makes it almost as slow as Java (gcj)?

      Because there is a C++ compiler for my target platform and not a Java virtual machine.

    33. Re:Avoid direct memory access by mrsbrisby · · Score: 1
      Because there is a C++ compiler for my target platform and not a Java virtual machine.
      GNU CC targets almost every platform, and it may be easier to port it to your target than you think. GCJ can compile to native code so a separate virtual machine isn't required.
    34. Re:Avoid direct memory access by tepples · · Score: 1

      GNU CC targets almost every platform, and it may be easier to port it to your target than you think. GCJ can compile to native code so a separate virtual machine isn't required.

      My app already compiles in G++. But does GCJ automatically support all platforms that G++ supports? And even if so, will the equivalent app in GCJ, along with the Java class libraries, fit in the target platform's 4 MB of RAM? Replacing this hardware with one that has more RAM would inflate the product's estimated cost of goods sold by a factor of at least five, as the product is intended to run on hardware that the end user is already likely to have. And will it be able to handle requests in real time without missing messages while stopping to System.gc()? And what about the I/O libraries provided by the hardware vendor? Can GCJ hook up to those?

  7. I don't. by WalterGR · · Score: 1, Redundant

    How do you go about making sure your code is secure? Especially if you have to write in a language like C or C++?

    I don't. I just open source my code, and other people find the security bugs for me. More eyeballs and all, ya know?

    ;)

    1. Re:I don't. by Anonymous Coward · · Score: 5, Informative

      Grammar tip: "Effect" is a verb. "Affect" is a noun.

      Um, how's that?

      Your poor grammar has a chilling effect on me. If I were you, I'd find a way to effect an improvement in your knowledge. Luckily it affects me only a little. But the fact that so few seem to understand that these two words are both verb and noun leaves me of sad affect.

    2. Re:I don't. by davermont · · Score: 1

      Actually: They're both nouns and both verbs.

    3. Re:I don't. by pedantic+bore · · Score: 1

      Grammar tip: dictionaries contain many useful facts.

      --
      Am I part of the core demographic for Swedish Fish?
    4. Re:I don't. by Anonymous Coward · · Score: 1, Informative
      Grammar tip: "Effect" is a verb. "Affect" is a noun.

      Perhaps your constant exposure to the poor grammar here has affected your ability to use it properly - I hear it's a common effect amongst Slashdot readers and posters.

      Oh, and as a few other people have stated, they can both be used either way, but the common usage is exactly the opposite of what you've stated.

      HTH, HAND.
    5. Re:I don't. by maxume · · Score: 1

      What about iffect and offect? Of course, everybody knows that yffect isn't a word.

      --
      Nerd rage is the funniest rage.
    6. Re:I don't. by peepleperson · · Score: 2, Funny

      Of course, everybody knows that yffect isn't a word. It's a small village in Wales.
    7. Re:I don't. by et764 · · Score: 1

      What poor grammar? The statement "'Effect' is a verb. 'Affect' is a noun." is a true statement. You even illustrate your understanding of this with your paragraph where you use each word correctly as both a verb and a noun. The GP did not say that effect is not a noun, or that affect was not a verb, just simply that effect is also a verb and affect is also a noun.

  8. Easy by $pearhead · · Score: 5, Funny
    Just make sure your buffers are really really REALLY big:

    char nooverflowbuffer[234523400];

    sprintf("Enter something:");
    scanf("%s", nooverflowbuffer);
    ... or maybe not ...
    1. Re:Easy by Anonymous Coward · · Score: 0

      How about realizing the overflows are not the only security problem out there. And any developer worth their bones would write functions that have explicit bounds checks anyways.

      C is a decent language, you just have to not "suck" at it. And lots of review. In the >5 years I've been working crypto I've had maybe a half dozen buffer problems (usually overruns not overflows).

      Everyone seems to naively assume that languages like Java or C# solve all these problems, but it's totally easy to have race conditions (for instance) in a Java application which allows "teh nasty" to happen.

      And god forbid you be working with cryptography, then you have to actually USE it right too (not just write secure code).

    2. Re:Easy by Anonymous Coward · · Score: 0

      You're not so far of as you may think. When people say that languages like Java prevent buffer overflow errors, they don't mean that the compiler will magically generate the correct code to handle the overflow situation. It can't, what is the correct(tm) solution? Throw the rest away? Read it in multiple passes? Make the buffer bigger? Stop the program with an error message? What Java does (at least with classes like string), is to simply make the buffer bigger when there isn't room enough. That won't work forever. First you'll run out of RAM (another fixed size buffer), and then virtual memory. So, basically the solution IS to make the buffer REALLY BIG, until it consumes all RAM and VM.

      (And after it runs out of RAM and VM, it will stop with an OutOfMemoryException, unless the box has trashed itself to death before that, making it into a nice DOS attack).

    3. Re:Easy by jaymzter · · Score: 0
      I'm no expert, but shoudn't that be

      char noverflowbuffer[234523400];
       
      sprintf("Enter something: ");
      scanf("%s, &noverflowbuffer);
      --
      If thou see a fair woman pay court to her, for thus thou wilt obtain love
    4. Re:Easy by swilver · · Score: 2, Informative
      Buffer overflows may not be the only security problem, but at the moment they are by far the most common security problem. A race condition MIGHT allow you some unauthorized access to certain things.. more likely however, it will just show up as a minor malfunction in the program without any security implications at all.

      It certainly won't allow you to execute arbitrary code in for example a Java application -- infact, you'd have to find a bug in the JVM itself or one of the native implementations of basic classes like String to have any chance of that. That is however highly unlikely given the amount of use these core parts of Java see.

    5. Re:Easy by gnasher719 · · Score: 3, Funny

      The second version seems more secure, because it doesn't compile.
      The first version seems to be quite secure as well, because it is likely to crash immediately, and obvious crashes will usually get fixed quickly.

      Hint: What is the format string in >> sprintf("Enter something: "); and where will the output go?

    6. Re:Easy by PacoSuarez · · Score: 1

      No, you are definitely no expert. The name of an array can be used to get a pointer to the first element, and that's how scanf expects you to specify a string.

    7. Re:Easy by h2g2bob · · Score: 2, Informative

      I'd suggest:

      #define BUFSZ 1024
      char buf[BUFSZ];

      printf("Enter something: ");
      fgets(buf, BUFSZ, stdin); /* the SECURE way to do it, don't even think of using gets() or scanf()! */
      strip_newline(buf, BUFSZ); /* some function to remove trailing newline */

    8. Re:Easy by Jerry+Coffin · · Score: 1
      fgets(buf, BUFSZ, stdin); /* the SECURE way to do it, don't even think of using gets() or scanf()! */

      You can use scanf perfectly well:

      scanf("%1023s", buf);

      Though, of course, actually doing so is fairly unusual. Of course, it's also possible to find buggy implementations of scanf that have (for example) fixed-size internal buffers...

      strip_newline(buf, BUFSZ); /* some function to remove trailing newline */

      One thing many people fail to note is exactly why fgets doesn't already do this. The trailing newline (or lack thereof) tells you whether you've really read the entire line, or there's more data waiting to be consumed. If you really want to do this, the library provides a function for the job -- albeit, it's a rather unusual use for this particular function:
      strtok(buf, "\n");
      does a perfectly fine job of stripping a trailing new-line.

      --
      The universe is a figment of its own imagination.
  9. Security by El+Lobo · · Score: 2, Insightful
    It is hard to be sure that your code have no bugs or security holes. That's because even the Hello world program is using implicity a lot of libraries/dependences that are not written by you and are sometimes very complex. For example, writting Hello World to the console invokes a string handling unit in any hight level languge. String handling units are per se complex unit and there may be a lot of bugs there that may affect your code's security if those bugs are exploited.

    Writting in C/C++ doesn't do the whole thing better. A strong/typed language like Delphi or a managed language like C# are less likely to have any buffer overflow type bugs, etc, but you never know. Code writting is not pizza baking.

    --
    It's time to realise that Abble's products are the biggest abomination these days. Just say NO to the dumb iAbble way!!
    1. Re:Security by beakerMeep · · Score: 1

      Apparently you have never suffered from disastrous cheese overflow.

      --
      meep
  10. How Do You Know Your Code is Secure? by Duds · · Score: 1

    Easy, I never ever run the program.

    1. Re: How Do You Know Your Code is Secure? by Rogerborg · · Score: 1

      But can you discount the possibility that your program may already be running (or not running) on a quantum computer somewhere?

      --
      If you were blocking sigs, you wouldn't have to read this.
    2. Re: How Do You Know Your Code is Secure? by Rik+Sweeney · · Score: 1

      Easy, I never ever run the program.

      You'd make a great Doctor:

      It hurts when I do this.... ouch!

      Don't do that then.

    3. Re: How Do You Know Your Code is Secure? by Oddscurity · · Score: 1

      Ah, but on a quantum computer it's running and not running at the same time.

      --
      Indeed!
    4. Re: How Do You Know Your Code is Secure? by Duds · · Score: 1

      On a quantum computer it's irrelevent since simply trying to see the program changes it anyway.

    5. Re: How Do You Know Your Code is Secure? by autocracy · · Score: 1

      Well, if a quantum computer oculd exist, it does and doesn't exist; therefore there must be a quantum computer. On a quantum computer, his code is running and not running at the same time. Therefore, his code is running in a crashed state. We're screwed. (types $world/0 into his quantum computer)

      --
      SIG: HUP
  11. Same way you hunt bugs by Llywelyn · · Score: 5, Informative

    0) Don't "roll your own" security unless absolutely necessary. Find someone else's implementations and work with those.

    1) Design the code for security, code to that design. I've seen of security bugs creep into code because it was never designed to be secure.

    2) Use static code checkers--such as Splint for C/C++ and FindBugs for Java--that look for security vulnerabilities.

    3) Peer reviews/code audits. Sit down with your code (and have others who know how to look for security vulnerabilities sit down with your code) and do a full review.

    Nothing is foolproof, but every little bit helps. It should be noted that all of the above also improve the overall quality of the code and reduce the number of overall bugs: Finding existent implementations of features that can be used can reduce maintenance and reduce bugs; Designing the code and putting it through a proper design review can catch a lot of logic problems and ensure that the code fits the requirements list--I've seen a huge number of synchronization bugs in Java simply because the author didn't know how to use synchronization properly; static code checkers find a lot more than just security bugs; and Peer Reviews/Code Audits can help isolate a variety of problems.

    --
    Integrate Keynote and LaTeX
    1. Re:Same way you hunt bugs by Anonymous Coward · · Score: 1, Interesting
      Don't "roll your own" security unless absolutely necessary. Find someone else's implementations and work with those.

      This is correct for crypto, wrong for everything else. I've often replaced third party authentication code that was above and beyond what was required in terms of complexity.

      Design the code for security, code to that design. I've seen of security bugs creep into code because it was never designed to be secure.

      In principle I agree, in the real world it's about finding a balance. You can't design away security bugs and you can't spend 60% of your runtime stuck in input validation and security procedures.

    2. Re:Same way you hunt bugs by autocracy · · Score: 2, Funny
      Yes, please continue to implement your own security.

      Especially focus on validating usernames and passwords against an SQL database. That's my favorite.

      --
      SIG: HUP
  12. The answer is simple - you never know by tuxlove · · Score: 4, Insightful

    Anyone who develops software knows the axiom - the number of bugs discovered in any piece of software is directly proportional to the amount of testing you perform on that software. From this, it follows that you can keep testing forever and at best only asymptotically approach bug-free code. Sounds hyperbolic, but I've observed it to be true in my experience. And as long as there are bugs, there are bound to be security bugs.

    You can only minimize the risk that security issues will be found with any software. The best way to do this is to perform a rigorous code audit, preferably by security professionals. And if you can, make the software open source. You get a lot more eyes staring at it for free that way.

    1. Re:The answer is simple - you never know by Rogerborg · · Score: 2, Informative

      Another issue with (manual) testing is that testers tend to pursue bugs aggressively in whatever area they first happen to find some, which means you get good depth coverage, but can end up missing out on testing whole areas of functionality.

      --
      If you were blocking sigs, you wouldn't have to read this.
    2. Re:The answer is simple - you never know by TheRaven64 · · Score: 4, Interesting
      Don't trust your own code. The reason OpenBSD is secure is party because the code is security audited constantly, but also partly because much of the system is written on the assumption that the rest of it is buggy. Isolate your code as much as possible. If you can get away with it, fork off separate modules and communicate between them over a well-defined interface. Validate everything that is received. Don't let any of your code run with more privileges than it needs; make good use of chroot and setuid. If you don't need to be able to access anything on the filesystem then the first thing you should do is make an empty directory and chroot there; that way an attacker who compromises your code can't do anything useful.

      The best advice I read was from the Erlang documentation. It suggested that you program defensively on a system level, but not on a module level. If a module receives input it can't understand, or thinks it is in an invalid state, the correct behaviour is for it to crash. A system of monitors should deal with failures of components, because they can determine how the failure will affect other components. There has only been one remote root hole in OpenBSD in the last ten years, and it would have been avoided if the OpenSSH developers had used this principle.

      --
      I am TheRaven on Soylent News
    3. Re:The answer is simple - you never know by shrykk · · Score: 1
      tuxlove wrote:

      Anyone who develops software knows the axiom - the number of bugs discovered in any piece of software is directly proportional to the amount of testing you perform on that software.
      With respect, I suspect this is a not-quite-appropriate extension of the maxim applied in manufacturing processes, that you can't test defects out of an item. This applies to pulling mass-produced objects off the assembly line and checking they perform to specification. You can test more items, and you can test them more rigorously, but this will keep increasing your defect rate. (You have to actually improve your processes, which leads to the continuous improvement idea, six sigma quality control, and numerous other buzzword-laden methodologies anyone who went to engineering school any time recently will remember as a welcome break from proper courses that had equations).

      In software, the finished product can be perfectly duplicated, so one could aim to produce software that actually performs as specified and doesn't misbehave. This is leaving aside the philosophical question of whether one can improve a piece of software for ever. And of course the bigger the project the more impossible this becomes in practice. But at least you don't have to check every copy of 'rm' and 'less' for defects as they come off the assembly line :)
      --
      #define struct union /* Reduce memory usage */
    4. Re:The answer is simple - you never know by mrchaotica · · Score: 1
      From this, it follows that you can keep testing forever and at best only asymptotically approach bug-free code.

      Yep, and this is why TeX version numbers asymptotically approach pi : )

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    5. Re:The answer is simple - you never know by tuxlove · · Score: 1

      You cannot compare software and assembly line methodology. When testing your average piece of software, say, a word processor, there are no arbitrary tolerances to test for, etc. And of course, as you have noted, software effectively copies perfectly, provably each time, so there will be no duplication error. But none of this has anything to do with my point, as you have so clearly pointed out in your assertion that none of this applies to software.

      Complex software is impossible to certify as bug-free. You can never prove or disprove that any piece of software is bug free, because it is impossible thing to test. You can't even prove that the things you DO test for actually work correctly all of the time, because maybe they only work correctly under lab conditions or are so intermittent that you'd have to test for 100 years to find problems with them.

      I read an assertion once that you can't even prove that helloworld.c, a single-line C program, is bug free. It follows from there that a million-line program is practically infinite in the ways it might not behave correctly. Because of the complexity, however, you are practically guaranteed that there are countless bugs to be found. Finding them all simply cannot happen. Anyone who does not grasp this cannot claim to understand software development. If you do not understand or agree, then ponder on the tree of woe.

    6. Re:The answer is simple - you never know by Simetrical · · Score: 1
      the number of bugs discovered in any piece of software is directly proportional to the amount of testing you perform on that software. From this, it follows that you can keep testing forever and at best only asymptotically approach bug-free code.

      Direct proportionality doesn't asymptotically approach anything. Maybe you want a decaying exponential (for number of bugs remaining) or something.

      Yes, yes, I'm an anal-retentive math major.

      --
      MediaWiki developer, Total War Center sysadmin
    7. Re:The answer is simple - you never know by Anonymous Coward · · Score: 0
      If you can get away with it, fork off (...)

      Oh c'mon. That was uncalled for. Why do you have to be such a meanie?

    8. Re:The answer is simple - you never know by nasch · · Score: 1
      From this, it follows that you can keep testing forever and at best only asymptotically approach bug-free code. Sounds hyperbolic, but I've observed it to be true in my experience.
      I think this would be true only if the expected number of new bugs resulting from each bug fix is at least one. That is to say, when making any change to the code, there's a possibility of introducing an abitrary number of bugs, including zero. If over time you introduce fewer than one new bug for each edit, then eventually there will be zero bugs - assuming you do nothing but fix bugs. So practically speaking (and why would you want to do THAT??) obviously you're very unlikely to get zero bugs, but over an infinite time frame, you might. Unless somebody who remembers probability better than I do can correct me.
    9. Re:The answer is simple - you never know by shrykk · · Score: 1

      Because of the complexity, however, you are practically guaranteed that there are countless bugs to be found. Finding them all simply cannot happen. Anyone who does not grasp this cannot claim to understand software development. If you do not understand or agree, then ponder on the tree of woe.

      Heh. My comment was based on the supposition that the axiom that more testing => more defects may have been directly taken from a different area (manufacturing) when in fact, if it applies, it applies in a rather different way. Sometimes ideas cross-pollinate without actually being relevant to the new area, and I want people to think before using them.

      Re-reading your original comment, there's nothing I actually disagree with, though it's perhaps a little defeatist. Even notwithstanding the continued existence of bugs, design decisions and better tools can make software more secure.

      --
      #define struct union /* Reduce memory usage */
    10. Re:The answer is simple - you never know by Alpha830RulZ · · Score: 1

      I tend to prefer Charles Brooks' axiom (from The Mythical Man Month): The number of bugs remaining in a piece of code is proportional to the number of bugs you've already found. Buggy pieces of shit tend to remain that way. I suspect that the security bugs are merely an instance of the general case.

      --
      I was taught to respect my elders. The trouble is, it's getting harder and harder to find some.
  13. What's the matter with C/C++? by mangu · · Score: 4, Insightful
    Why do people keep this meme that C/C++ is so insecure? Remember, deep down inside the other languages, there often is a compiler, library, interpreter, etc written in C/C++.


    It's not that C/C++ is so insecure by itself, the problem is that programmers may not have used the best programming practices. There are plenty of libraries for handling strings and memory allocation in C, in C++ there are string and storage classes that do as much or as little checking as you need.


    When you are an expert programmer there are places where you need more efficiency than the super-safe string routines can give you. It's the job of the expert to determine exactly how to balance efficiency against security, and only C/C++ can give you this balance.

    1. Re:What's the matter with C/C++? by Anonymous Coward · · Score: 5, Funny

      'It's not that C/C++ is so insecure by itself'

      yeah a gun by itself is not insecure either....
      try giving it to a baby.....
      well I prefer a baby with a knife...I can still run faster than him...

    2. Re:What's the matter with C/C++? by Viol8 · · Score: 4, Insightful

      C/C++ are very powerful languages because they let you do pretty much what you like. But with this freedom comes the ability to shoot yourself in the foot badly either due to design errors, sloppy programming or just genuine mistakes. Personally I don't mind this risk but other people (usually the types who knock C/C++) can't really function in an enviroment that doesn't hold their hand and protect them from their own mistakes. Horses for courses.

    3. Re:What's the matter with C/C++? by Anonymous Coward · · Score: 0

      Remember, deep down inside the other languages, there often is a compiler, library, interpreter, etc written in C/C++.

      And remember deep down inside C/C++ there is assembler! ;-)

      I think we should just look upon programming languages as the tools that they are, in the right hands a true expert can create masterpieces with almost any language and in the hands of an idiot they can break even the smartest language. Indeed it could be said that there is now a "general" problem not just with security due to the fact that programming has now been dumbed down so much to the point that many proper programmers now spend their lives either replacing badly written access databases, excel macros or getting requests/complaints from someone who hasn't a clue what they are doing as they try to reinvent the wheel as a square block.

      When I was taught to program I was taught to design the program to do the task correctly first and make it look pretty later. Unfortunately with the advent of "visual programming" we now see the modern approach of people writing programs to look pretty first and then only later putting functionality in such as security. That is to say that they don't even give a thought to security when they are busy putting their 3 big buttons onto their macro launcher.

      Don't get me wrong I'm not totally against visual programming, I just feel the interfaces should encourage people to write the functional part first (with security) and then make the front end look pretty later. In the same way that it annoys the hell out of me to see animation for the sake of animation when the underlying task is given second priority. (e.g. copying files in windows) - it looks pretty but it now takes forever for the task to happen!

      In addition I also think that most companies should stop using their intern/students, junior/novice programmers to write their installation programs as that would resolve a lot of install/removal problems in the world. Anyone who knows coding knows what I mean here, the newbies are asked to write either the install or the launcher. Many a time a decent program has been dropped due to someone being unable to write a install program, even with helpful advent of NSIS you still see people who can't even us NSIS correctly - scary !

    4. Re:What's the matter with C/C++? by Anonymous Coward · · Score: 1, Interesting

      max planck, the famous german physicist whoose name is immortalized in the planck, once observed that it is not tthat scientists retrain themselves as theorys become obsolete, but that the new genrations don't learn the errors of hte past

    5. Re:What's the matter with C/C++? by TheRaven64 · · Score: 2, Interesting

      Remember, deep down inside the other languages, there often is a compiler, library, interpreter, etc written in C/C++. Not in the case of Smalltalk. The Squeak VM is written in a subset of Smalltalk which is compiled by a compiler written in Smalltalk into native code. Most of the Java VM and compiler, I believe are written in the same way.

      There are plenty of libraries for handling strings and memory allocation in C, in C++ there are string and storage classes that do as much or as little checking as you need. Once you have added enough to a language that it no longer looks like the original, then it's time to ask yourself if you picked the correct language for the job to start with. I could write a dynamic dispatch mechanism with inheritance for use in C, but I would start to wonder if I shouldn't really have written the entire project in Objective-C instead.
      --
      I am TheRaven on Soylent News
    6. Re:What's the matter with C/C++? by CDarklock · · Score: 2, Interesting

      > Why do people keep this meme that C/C++ is so insecure?

      Because bugs don't belong to programmers, they belong to code.

      Imagine the difference between "I fixed a Linux kernel bug", which earns you much respect from the community, and "I fixed one of Linus Torvalds' bugs" - which is a rather offensive thing to say.

      So while the insecurity is the programmer, not the language, we can't blame the programmer. It's simply not acceptable.

      --
      Microsoft cheerleader, blue flag waving, you got a problem with that?
    7. Re:What's the matter with C/C++? by arevos · · Score: 4, Insightful

      Why do people keep this meme that C/C++ is so insecure? Remember, deep down inside the other languages, there often is a compiler, library, interpreter, etc written in C/C++.

      C and C++ have a larger domain that can suffer from buffer overflows than languages with automatic memory management. In C, a buffer overflow can potentially occur at any point in your source code. In a language which automatically manages memory and checks bounds, the possible points at which buffer overflows can occur are reduced. This does not necessarily make the application more secure, but it does mean that there are less points at which it can be compromised.

      When you are an expert programmer there are places where you need more efficiency than the super-safe string routines can give you. It's the job of the expert to determine exactly how to balance efficiency against security, and only C/C++ can give you this balance.

      I'm not sure that the efficiency increase from dropping boundary checks is often necessary, except possibly in high-end 3D games. Also, many languages allow for binary libraries written in C, so it would be possible to write an application in C#, Python, Ruby or whatever, and farm out any efficiency-critical routines to a library.

    8. Re:What's the matter with C/C++? by noidentity · · Score: 1

      Another very common meme is "C/C++".

    9. Re:What's the matter with C/C++? by Decaff · · Score: 2, Informative

      Why do people keep this meme that C/C++ is so insecure? Remember, deep down inside the other languages, there often is a compiler, library, interpreter, etc written in C/C++.

      Which is irrelevant. That code can be thoroughly tested and safe, even with the fundamental issues of C++. What matters is your code. You probably won't get the chance to test that code thousands or millions of times the way the compiler/library or interpreter has been.

      It's not that C/C++ is so insecure by itself, the problem is that programmers may not have used the best programming practices. There are plenty of libraries for handling strings and memory allocation in C, in C++ there are string and storage classes that do as much or as little checking as you need.

      C/C++ IS insecure by itself, because of what it allows you to do. No programmer is perfect, and we all make mistakes. Driving without a safety belt is fundamentally less safe, and you can't argue it away by talking about 'people not driving skillfully enough'.

      When you are an expert programmer there are places where you need more efficiency than the super-safe string routines can give you. It's the job of the expert to determine exactly how to balance efficiency against security, and only C/C++ can give you this balance.

      I would be very surprised to know exactly when you think this is the case. If it is, it is for the most specialised circumstances. The problem with C/C++ is you have this division between safe (with checks) or fast. Other languages get around this problem, by including safety, but allowing the safety checks to be optimised away by code analysis, often at run time. For example, you could have code something like this:

      int [] array = new int [4];
      for (int i = 0; i 4; i++) array[i] = i;

      The compiler/runtime can analyse this code, and because it is obvious that the bounds of 'array' are never exceeded here, remove any checking and optimise hugely.

      It is a myth that you need to balance efficiency against security the C/C++ way.

    10. Re:What's the matter with C/C++? by Anonymous Coward · · Score: 0

      But when it comes right down to it, C really is high level assembly language. With a macro assembler you very often wind up with aseembly language that differs from "normal C" only it's direct use of registers and the stack. So deep inside it's oopy heart even smalltalk is C, it just doesn't acknowledge the fact.

      That's the real reason the C model persists and will continue to persist, the computing world still needs a standard high level assembly language and won't give it up anytime soon.

    11. Re:What's the matter with C/C++? by Tyler+Durden · · Score: 2, Insightful

      And that's the problem these days. Too many babies using C/C++.

      --
      Happy people make bad consumers.
    12. Re:What's the matter with C/C++? by canuck57 · · Score: 2, Insightful

      yeah a gun by itself is not insecure either.... try giving it to a baby.....

      There is the crux of the C/C++ problem, we give an oozie to to 3 year olds without the training and knowledge. 9/10 C/C++ programmers I ever interviewed failed to properly explain how pointers work. Those that did answer pointer questions correctly tend to have programmed more securely than those that put */&/** by memory.

      It also comes down to money, a good C/C++ programmer isn't cheap.

    13. Re:What's the matter with C/C++? by Anonymous Coward · · Score: 0

      we give an oozie to to 3 year olds

      What's an oozie? A sore that's emitting pus?

    14. Re:What's the matter with C/C++? by Decaff · · Score: 1

      That's the real reason the C model persists and will continue to persist, the computing world still needs a standard high level assembly language and won't give it up anytime soon.

      The real problem was the widespread decision to use such a high level assembly language as if it were suitable for general purpose development.

    15. Re:What's the matter with C/C++? by Anonymous Coward · · Score: 1, Funny

      "with great power come great responsabilities" Spiderman's Uncle - 2002

    16. Re:What's the matter with C/C++? by grammar+fascist · · Score: 2, Insightful
      Personally I don't mind this risk but other people (usually the types who knock C/C++) can't really function in an enviroment that doesn't hold their hand and protect them from their own mistakes.

      There are plenty of us who are perfectly capable of functioning in that environment but choose not to, preferring to focus mental energy on algorithms rather than silly implementation details like whether that pointer I've got points to something stack-allocated or heap-allocated. Besides that, I do mind the risk, because I have the mental capacity and maturity to understand that, even though most of the code I write that compiles is also correct, I'm not perfect.
      --
      I got my Linux laptop at System76.
    17. Re:What's the matter with C/C++? by Tyler+Durden · · Score: 1
      OK, so in your example variable array is a full-fledged object. As such, in this language, the program tracks the number of references to the object to know when this count goes to zero. Once this happens, a separate garbage-collection thread will run at some time we cannot predict to clean up the space this object is taking up. (As an aside, this is why finally clauses are needed in Java but not C++. In C++ the time at which objects are destroyed are well-defined, so we can use destructors to do necessary clean up precisely when we're leaving a try block.)

      Compare this to the C/C++ equivalent. There array is simply a block of memory. This memory is cleaned up precisely after we exit the block in which it was defined. Since it takes approximately 2 brain cells to know that the quantity we check in the for loop is the same as the number of elements we define array as having, there is no need to have any built-in bounds checking in the language in the first place.

      I fail to see any big advantage with Java in this case. Quite the opposite.

      --
      Happy people make bad consumers.
    18. Re:What's the matter with C/C++? by Digital_Quartz · · Score: 1

      I'm not worried about me; I don't need protection from my own mistakes. If I'm writing software for a radiation therapy machine, or a phone switch which handles 911 calls, I want to make sure that the people who literally put their lives in my hands will be protected from my mistakes. And not just my mistakes, but the errors of the hundreds of other people who work in my company.

    19. Re:What's the matter with C/C++? by Anonymous Coward · · Score: 0
      What's an oozie? A sore that's emitting pus?

      You mean, like open sores?
    20. Re:What's the matter with C/C++? by swillden · · Score: 1

      There are plenty of us who are perfectly capable of functioning in that environment but choose not to, preferring to focus mental energy on algorithms rather than silly implementation details like whether that pointer I've got points to something stack-allocated or heap-allocated.

      This is why I prefer C++ over C. It isn't really a reason to choose Java or similar over C++, though. There *are* good reasons to use other languages, but this isn't one of them.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    21. Re:What's the matter with C/C++? by Anonymous Coward · · Score: 0

      Buffer overflows are not the worst case, except perhaps security wise. Much worse is dangling pointers, uninitialized member variables, lack of multi-thread support, etc.

    22. Re:What's the matter with C/C++? by StikyPad · · Score: 1

      I think the word you're looking for is Uzi. Perhaps not though..

    23. Re:What's the matter with C/C++? by Decaff · · Score: 1

      OK, so in your example variable array is a full-fledged object.
      As such, in this language, the program tracks the number of references to the object to know when this count goes to zero. Once this happens, a separate garbage-collection thread will run at some time we cannot predict to clean up the space this object is taking up. (As an aside, this is why finally clauses are needed in Java but not C++. In C++ the time at which objects are destroyed are well-defined, so we can use destructors to do necessary clean up precisely when we're leaving a try block.). Compare this to the C/C++ equivalent. There array is simply a block of memory. This memory is cleaned up precisely after we exit the block in which it was defined. Since it takes approximately 2 brain cells to know that the quantity we check in the for loop is the same as the number of elements we define array as having, there is no need to have any built-in bounds checking in the language in the first place.


      Well, the history of C and C++ use over decades is that many developers don't possess those particular 2 brain cells, as buffer/array overrun problems are widespread.

      I fail to see any big advantage with Java in this case. Quite the opposite.

      You haven't actually given any reason why the Java approach should be disadvantageous - you have simply presented a series of facts.

      The Java approach is unquestionably safer. And garbage collection can be extremely efficient - just as efficient as manual memory management, even on real-time systems.

    24. Re:What's the matter with C/C++? by Tyler+Durden · · Score: 1
      Well, the history of C and C++ use over decades is that many developers don't possess those particular 2 brain cells, as buffer/array overrun problems are widespread.

      I'd much rather buffer overrun exploits be taken care of through the CPU and the OS using the NX bit. If it was used, most attempts to execute code with a buffer overrun would instead result in crashing the program, as should happen. This is acheived without the overhead from Java which you refuse to admit exists.

      You haven't actually given any reason why the Java approach should be disadvantageous - you have simply presented a series of facts.

      Construction overhead from an object that could have simply been a block of memory. Clean-up of objects that happens at unpredictable times, necessitating more complicated and less clean code with convoluted finally blocks. I'd much much rather have a language where I can deduce exactly when clean-up events happen and when. Let me worry about how to make my programs safe without a language forcing my code to be cluttered because it wants to "help".

      This isn't easily implied by my list of facts?

      The Java approach is unquestionably safer.

      The same programmer who cannot make your program safe in C/C++ is the exact same person who would attempt to use null references in Java or introduce memory leaks by failing to call close() methods for objects that need it or leave other objects with references to them long after they are needed.

      And garbage collection can be extremely efficient - just as efficient as manual memory management, even on real-time systems.

      Bullshit. There ain't no such thing as a free lunch. There is definitely a place for Java. But to say that there is no longer a place for C/C++ is just a result of willful ignorance.

      --
      Happy people make bad consumers.
  14. Grammar by noz · · Score: 2, Insightful
    Marucs Ranum notes taht [...]
    Marucs' code is more secure than Zonk's editing.
    1. Re:Grammar by Anonymous Coward · · Score: 0

      I think his name is Marcus, not Marucs.

  15. Some possibilities by AArmadillo · · Score: 2, Insightful

    You cannot know for sure (unless you want to develop code by mathematical proof, which requires a considerable amount of effort). However, you can do some things to help prevent buffer overflows and security problems in general: - encapsulate all buffer access, and make the interface overflow-safe. Then you need only ensure your encapulation is secure. - use a static code analysis tool that detects buffer overflows. I do not know of any open source ones off the top of my head, but I remember seeing an article on slashdot a few months ago about a new open source static analysis tool - avoid unsafe functions. Nearly all standard C functions that deal with buffers are unsafe (that is, a typo or oversight can give you a difficult to detect buffer overflow). Sprintf and strcpy are common culprits off the top of my head. If you're writing for Windows, the Microsoft extensions to the standard library have equivalent 'secure' functions (usually postfixed with _s). I do not know if there is an open source equivalent. - Use your compiler's buffer overrun detection. I think this is -fmudflap for gcc. That's all I can think of for now.

    1. Re:Some possibilities by zCyl · · Score: 5, Funny
      You cannot know for sure (unless you want to develop code by mathematical proof

      In the words of the great Donald Knuth, "Beware of bugs in the above code; I have only proved it correct, not tried it."
    2. Re:Some possibilities by Anonymous Coward · · Score: 0

      Cyclone is a dialect of C that uses a type system to guarantee zero buffer overflows. Of course, this means a few operations will be slower than C, but the slowdown shouldn't be too bad considering that Cyclone was designed for efficient systems programming, like writing drivers.

      I believe it's open source and contains safe C library wrappers as you describe.

  16. Easy... by D-Cypell · · Score: 1
    How Do You Know Your Code is Secure?


    Easy! It doesn't run :)

  17. Valgrind by chatgris · · Score: 5, Informative

    By using valgrind. It's a virtual machine of sorts that runs your code and checks for any memory problems at all, including use of uninitialized memory. Combine that with thorough test cases, and you can be virtually assured that you have no memory errors in your C/C++ code.

    However, security is a lot more than buffer overflows... but at least it brings you up to the relative security of Java, with speed to boot.

    --
    Open Your Mind. Open Your Source.
    1. Re:Valgrind by Anonymous Coward · · Score: 0
      ... Combine that with thorough test cases ...
      That is the problem, right there. Generally you will not get 100% code coverage in tests, i.e. it is is not possible to test the program with all possible inputs and all possible error conditions.
    2. Re:Valgrind by Tony+Hoyle · · Score: 1

      Nope. Valgrind will find crashing bugs, not security issues.

      It can only find actual overflows as they happen not potential overflows. You need code analysis to do that - there are a number of tools on the market that can do that kind of analysis (not sure if there are any free/oss ones though.. never seen any).

    3. Re:Valgrind by Anonymous Coward · · Score: 0

      And the parent comment is a fine example of why there are so many software flaws.

    4. Re:Valgrind by dkf · · Score: 1

      It's not quite as bad as that; you can actually win with enough effort. Devising a properly thorough suite of test cases is equivalently hard to demonstrating that the program is formally correct, but not harder. OK, this is because a thorough suite of test cases (that all pass, natch!) is really exactly a proof of correctness; you need all the same mental tools and thought processes. It's very difficult, but not impossible.

      But most programmers punt on all that, and use the "hope and pray" approach to verification. For lots of code (especially temporary stuff like small shell scripts) that works well enough.

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    5. Re:Valgrind by Carewolf · · Score: 1

      Coverage provides this service for free for most larger open source projects.

    6. Re:Valgrind by Krunch · · Score: 1
      Combine that with thorough test cases, and you can be virtually assured that you have no memory errors in your C/C++ code.
      Well, no.
      --
      No GNU has been Hurd during the making of this comment.
    7. Re:Valgrind by Anonymous Coward · · Score: 0

      why did the OP get marked as informative. He is completely incorrect and if this is the method he uses to ensure lack of memory security problems such as overflows his code is probably swiss cheese, Valgrind does not detect potential buffer overflows and neither do test cases. Only good code reviews or perhaps fuzzing to try to get your code to crash will find those.

    8. Re:Valgrind by Anonymous Coward · · Score: 0

      I thought it was called Coverity (http://www.coverity.com/html/prod_prevent.html)

  18. Assume failure by zCyl · · Score: 5, Insightful

    Every function should be designed with the assumption that its input is faulty, and should have safe failure modes for every possible value and all possible content. Any unsafe external libraries must be wrapped in handlers which verify the data being passed to them with a similar mindset. Do not EVER presume data will be of a certain form, or that a function will be used a certain way. If sequential routines are becoming long such that you cannot verify the accurate function or the absence of a buffer overflow immediately in your head, then stop and look for a way to break it down into smaller abstract pieces.

    Combine this mentality with the usage of safe classes as datatypes whenever possible, so that you can wrap your input verification into the functionality of the classes. If prudent, wrap external library routines in classes which manage the interaction with them, and which verify the data content being passed.

    Use test suites to test every component of your program, and be sure to include invalid and pathologically insane input in your test suites.

    Do not trade security for efficiency. And don't forget to cross your fingers.

    1. Re:Assume failure by TheRaven64 · · Score: 1

      Do not trade security for efficiency. And don't forget to cross your fingers. I disagree on this point. Only trade efficiency for security when you know what you are doing. If you are writing HPC code that is going to run on a private supercomputer or cluster, or code that will be run in a VM which is then thrown away, you can do this. Whenever you do, however, add a #warning line reminding users of the code where it's insecure so that anyone who wants to take the code and use it in production will know what to fix.
      --
      I am TheRaven on Soylent News
    2. Re:Assume failure by TheRaven64 · · Score: 4, Funny

      Fuck off, private functions below the public API should never have to check their input. I completely agree. There are no bugs in my code, just in the code of people calling my code.
      --
      I am TheRaven on Soylent News
  19. Re:Don't use C++ as if it was only "C with classes by Viol8 · · Score: 2, Insightful

    The mostly STL gets rid of the old problems such as buffer overflows but introduces new ones that can a lot more subtle and harder to track down such as deep/shallow copy issues. Personally (and I'm probably in the minority) I prefer to deal with the old fashioned bugs since you can usually guess where they're happening whereas in a highly abstracted C++ program using the STL with lots of objects being copied and references flying around it can be a LOT harder to figure out whats really going on , especially since different compilers do different things under the hood.

  20. Perspective by Anonymous Coward · · Score: 0

    Change your perspective on the issue. The "insecurities" are a result from what the programmer has written. Rather than viewing them as branches of execution that should not happen, view them as unintended parts of the program that do happen. If you do not want your program to behave that way, then do not write your code that way.

    Think about the code as you are writing it. Think about every possible outcome of executing the code you have programmed.

    I know the last two are difficult with the hustle and bustle we live in now, but I don't know of a less time consuming solution.

    Unless you can account for every instruction in your code, you do not know that your code is secure,

    Good luck.

  21. Just Say No by iliketrash · · Score: 0, Troll

    "How do you go about making sure your code is secure? Especially if you have to write in a language like C or C++?" Don't write in C or C++. Duh. Where is it written that all software must be written in C or C++? Is anyone capable of independent thought? There are plenty of fine languages that are safe. Ada comes to mind. Maybe others will come to your mind (if you have one).

    1. Re:Just Say No by hAckz0r · · Score: 2, Insightful
      Ada comes to mind.

      Ok, What language is your Ada compiler written in? There are very few self-hosted languages that do not rely on "C" at some level. Also, the OS and the system libraries were written in C. At some level you need to deal with the stated problem. All that being said many people are probably better off with Ada unless they actually "study" software security on a daily basis.

    2. Re:Just Say No by Anonymous Coward · · Score: 0

      Well its not that simple. A lot of softwares require to use C/C++ for efficiency/performance. You can't always use Java or .NET or Scripting languages for those tasks.

    3. Re:Just Say No by gbjbaanb · · Score: 1

      The stated problem is obviously programmers who don't know enough about what they're doing and require an easy-to-use language that makes up for their shortcomings. :-)

    4. Re:Just Say No by arthas · · Score: 1

      Or the coders should really try to learn how to use C/C++ and whatever APIs (libraries) they are using correctly...

      Oh, and the people who code the libraries and stuff like that should design, implement and document their APIs properly so that the coders using those libraries actually have complete and accurate documentation available!

    5. Re:Just Say No by Anonymous Coward · · Score: 0

      GNAT is written in Ada: https://libre.adacore.com/ But Ada is a social language and is quite friendly with C and other languages and can therefore interface with either quite easily. It's trivial in Ada to write weak C bindings and even an Ada newbie could do it. This is because Ada was not designed to eliminate C which will always have a place when people need portable assembler and so instead, accepts this fact and makes it very easy to work with C and even C++ (not to mention Fortran, COBOL, and assembly). She's a practical and safe language, not an idealistic one. C fits a niche which Ada doesn't try to usurp. Now C++, that's another story....

    6. Re:Just Say No by hackstraw · · Score: 1

      "How do you go about making sure your code is secure? Especially if you have to write in a language like C or C++?" Don't write in C or C++. Duh. Where is it written that all software must be written in C or C++? Is anyone capable of independent thought? There are plenty of fine languages that are safe. Ada comes to mind. Maybe others will come to your mind (if you have one).

      I have a mind, I've heard of Ada, and I've read about it, but I've never touched an Ada compiler.

      So, where is it written that all software must be written in C or C++? Its not, but TONS of software and especially existing libraries are written in C/C++.

      Can Ada be used for Linux kernel modules or Windows device drivers? I know C and possibly C++ can be used. Does Ada have hooks to common libraries like SSL and zlib?

      How proven is the Ada compiler for Solaris, Linux, Windows, and AIX?

      I've got years of experience with C/C++, zero with Ada, if you really want that code to be written yesterday, how long will it take me to be as proficient in Ada as I am in C/C++?

      I ask people all the time why the still use Windows just like you are asking about why people still use C or C++. The difference in my question is that there is a clear migration from Windows via virtualization and/or using alternatives to Windows specific solutions. The fact of the matter is that change takes time and effort, and people are fundamentally lazy and comfortable with what they are already familiar with. Couple that with ignorance of there being a better way, and your stuck with the lowest common denominator, like it or not.

    7. Re:Just Say No by maxwell+demon · · Score: 1

      Scripting languages are no more secure than C or C++! Ever heared of code injection attacks?

      --
      The Tao of math: The numbers you can count are not the real numbers.
    8. Re:Just Say No by iliketrash · · Score: 2, Insightful

      Ada is comparable to C and C++ in the area of "efficiency/performance." The misconception which you propagate disappears when fair comparisons are made. Remember that Ada is used in many embedded real-time applications; indeed, that is much of the reason that it came into existence in the first place.

    9. Re:Just Say No by Anonymous Coward · · Score: 0
      As someone else mentioned, Ada was originally designed as a safety critical embedded language (a field in which it still dominates) and so one can of course write drivers with it (though I doubt you'll see many for mainstream OSes). As for compilers, GNAT is the GNU Ada compiler and runs on many platforms. As for it being proven, Ada compilers are required to pass much more rigorous tests then C or C++ compilers in order to call themselves Ada compilers. So yes, GNAT is a free and proven Ada compiler (it even already supports Ada 2005) that will run on all of the above OSes since it's a part of GCC. As for libs, SSL, is supported in AWS and there is a thick binding for Zlib here. But also not that Ada has built in interfaces for C (and even C++ in Ada 2005) and it's trivial to write weak bindings for existing C libraries if none exist (though most do already). As for learning, Ada is pretty easy to learn and will look like Pascal or Delphi. Like C++ it's a big language, but over all it should be easy to learn if you're curious and have some time. The biggest hurdle to get over is the strong static typing of Ada. If you've never programmed in a language like this (ML for example) it will probably seem like coding in a "police state." But once you get over this little hurdle, you may just end up loving it since the compiler catches so many things at compile time that will be mysterious linking errors in languages like C++.

      But all that being said, Ada isn't trying to compete with C or C++, instead it works with them while still being an innovator in areas like concurrent programming. Although I would certainly say that Ada does everything these languages do better, the bottom line is there's a lot of C/C++ code out there (not to mention Fortran and COBOL in their respective domains) that Ada has built in interfaces too making it a very realistic and practical language. Good luck!

    10. Re:Just Say No by iliketrash · · Score: 1

      You ask some good questions, especially considering that my original post smelled of flaimbait.

      I have a mind, I've heard of Ada, and I've read about it, but I've never touched an Ada compiler.

      You may touch an Ada compiler for free 8^) since Ada is an official member of gcc. It is therefore available for any platform for which gcc is available. You may download from gcc.gnu.org or better (pre-compiled) from libre2.adacore. It is called GNAT and is written in Ada (at least the front end is.)

      So, where is it written that all software must be written in C or C++? Its not, but TONS of software and especially existing libraries are written in C/C++.

      Can Ada be used for Linux kernel modules or Windows device drivers?

      Absolutely.

      I know C and possibly C++ can be used. Does Ada have hooks to common libraries like SSL and zlib?

      As another poster commented, it is trivial (really) to make Ada bindings to C libraries. The "connection" is an official part of the Ada language specification. I did this recently for a plotting library written in C called PLplot plplot.sourceforge.net. I was just learning Ada and knew even less C. Most of my effort was involved in learning enough C to get the job done. I have posted information about these bindings at http://homepage.mac.com/oscarruitt/plplotinada/plp lot_ada.html. Note that this software is not yet released and is still under review by the PLplot folks; the usual disclaimers about suitability and nonliabiity apply.

      How proven is the Ada compiler for Solaris, Linux, Windows, and AIX?

      I'm not sure what you mean by "proven," but Ada is surely as proven as C and C++ is for these platforms. Ada can do anything that C and C++ can, as far as I know. Ada compilers typically undergo a notoriously stringent testing suite. When you fly on modern commercial jet aircraft, you're flying Ada. Post your question to comp.lang.ada and you'll get answers from actual Ada experts.

      I've got years of experience with C/C++, zero with Ada, if you really want that code to be written yesterday, how long will it take me to be as proficient in Ada as I am in C/C++?

      Tough question. Again, others with more experience in all of these languages can answer better. I'll answer this way at the risk of sounding prejudiced: You can become proficient in the subset of Ada that "covers" C and C++ in less time than it took you to learn them. Also, once you achieve some level of proficiency in Ada, it is commonly reported that development time is less than for C/C++. And Ada is said to excel in long-term maintenance of large projects.

      Personally, I (like everyone else) have looked time and time again at getting serious with C. (I first learned to program in 1973 and have used many languages.) Maybe I'm lucky, but I've always had the final choice in what languages I use. I am a big proponent of knowing several languages and choosing the best one(s) for the job. Not only has C struck me as being inappropriate for every programming task that I have had with respect to reliability, it has also struck me to be hard to learn and even harder to read. Ada, on the other hand, has a clean, consistent syntax and of course is designed from the ground up to be safe.

      I ask people all the time why the still use Windows just like you are asking about why people still use C or C++. The difference in my question is that there is a clear migration from Windows via virtualization and/or using alternatives to Windows specific solutions. The fact of the matter is that change takes time and effort, and people are fundamentally lazy and comfortable with what they are already familiar with. Couple that with ignorance of there being a better way, and your stuck with the lowest common denomina

    11. Re:Just Say No by Duds · · Score: 1

      Great, I'll just go tell my mutli million dollar turnover employer we need to spend 18 months rewriting our product in another language because "This guy on slashdot said so"

  22. Easy by Sodki · · Score: 0, Flamebait

    How about not using languages that allow buffer overflows?

  23. Don't let them use it where it matters by Anonymous Coward · · Score: 5, Funny

    I let my code have evident, gaping security flaws and make them well known. This way people will never use it in situations where security matters.

    regards,
    The author of sendmail

  24. String overflows by Rik+Sweeney · · Score: 2, Informative

    I think for some people, moving from using a language like Java to using C can cause them a multitude of problems since there's no bounds checking by default and overruns aren't caught.

    For example, I recently fixed a bug Blob And Conquer to do with Strings, the code was something like this:

    char nm[2];

    nm[0] = mission[11];
    nm[1] = mission[12];

    The code then went on to doing a

    missionNum = atoi(nm);

    Most of the time, this'd work OK because of the way atoi works. Other times though it'd stray off into other memory and pick up a random number and return a three or more digit number instead.

    Obviously there's an easy way to fix it.

    1. Re:String overflows by Anonymous Coward · · Score: 0

      WOW!

      Now you are a full fledged programmer! Let's all be complacent in our limited knowledge and fool ourselves that since we know hot to program, we know everything else! This is because we have inherited the world, like "Revenge of the Nerds" has taught us. Never mind that we are the butt of jokes by mathematicians, physicists and other real scientists! We can just continue on having undeserved arrogance, saying "OMG YOU DONT KNOW WHAT VIRTUAL MEMORY IS LOLOL"

    2. Re:String overflows by Tony+Hoyle · · Score: 1

      That's just college level programming though.. nobody would make that kind of mistake who had any experience.

      99% of the time that code would just crash, or the compiler/runtime would throw up an error saying what you'd done. If anyone actually committed something like that on my watch they'd be in trouble.

    3. Re:String overflows by hackstraw · · Score: 1
      Obviously there's an easy way to fix it.

      Yup. A rewite by a competant programmer, or at least some kind of code review.

      char nm[2];

      nm[0] = mission[11];
      nm[1] = mission[12];


      followed by an atoi(nm) is absolutely silly.

      First, if you use strings in C, you MUST null terminate them unless you REALLY know what you are doing. So, nm should be nm[3], and nm[3] should be 0. 99% of the time, I use strtol() or sscanf() instead of atoi() because I can detect errors with those other guys, but not with atoi(). The Linux manpage for atoi says:

      The atoi() function converts the initial portion of the string pointed
                    to by nptr to int. The behaviour is the same as

                                  strtol(nptr, (char **)NULL, 10);

                    except that atoi() does not detect errors.


      In summary, I only use atoi when I'm lazy for test-preproduction code, 99% of the time its for commandline arguments to convert them to ints for testing my code. I don't see a reason to use atoi for any code that is actually expected to work. Especially since over 99% of the time you are using atoi to convert input from an untrusted source.

      This is why we have discussions like this.

    4. Re:String overflows by Anonymous Coward · · Score: 0

      > So, nm should be nm[3], and nm[3] should be 0.

      if nm is declared char nm[3], the last legal index is 2. nice way to lecture him and then make a newbie error yourself.

  25. Re:Don't use C++ as if it was only "C with classes by Diablo1399 · · Score: 3, Insightful

    You would sacrifice the flexibility and usefulness of the STL to get a class of bugs that are old and well-known? Hardly seems like a fair trade-off to me.

  26. Proving the Unprovable by Sub+Zero+992 · · Score: 2, Insightful

    How do you validate code for correctness? Well, either you use some cool formal specification language, such as Z, and then spend a great deal of time and effort validating (which is actually very advisable for critical code in, say, device controls for medical equipment) or you use blind luck and "proven" techniques, collectively known as Good Programming Practice.

    Traditionally it has been important to "specify and validate" requirements acribically, in the belief that this is was the way to write good code. This is partly true, but that way can quickly turn your process into a dinosaur - stifling change and preventing improvement because of non-compliance with "The Requirements".

    You can try "defensive coding", which really treats all messages with great suspicion, messages being an old term for parameters. This is a cool technique, but can lead to slower code than necessary, and can lead to some bug being buried if code attempts to heuristically correct for "bad" messages (there is rarely any way to formally specify what is "bad"). You can use LINT tools (and there are very many, very sophistacted tools) which will catch a whole lot of stuff before it leaves the developer's screen. You can try practices such as pair programming and independent code inspection. On the coding side, you can even try (gasp) such methods as test driven development and contract based development.

    On the testing side, there is nothing quite like having an experienced, qualified, motivated and _empowered_ testing team. A testing team which knows how to find bugs, knows how to communicate with coders and has the power to step defects going in to production. A technique I particularly like is defect insertion - secretly insert 10 bugs into the code base and see how many get squashed, this will give you an estmate of how many defects your process doesn't find. There are other cool techniques too, some based on mathematical analysis of the code's attribute - the more complex the code the costlier it is to maintain.

    Opening up the codebase to many people might well increase the chance that someone will find the line which causes an error - but IMHO no one goes around looking for bugs unless they are looking for weaknesses. And there we have another (unethical) method - pay some hacker doodz to 'sploit your code. Hopefully they will not find a higher bidder LOL.

    All of these methods are likely to increase development effort and cost, decrease the number of defects, increase user satisfaction, decrease maintainance costs and increase well-being and harmony. So it is a trade off, perfect code is incredibly difficult to create - the question is what level of perfection are you (and your customers) willing to pay for. Problems mostly arise when expectation does not meet reality - some flakiness in an F/oss application suite is more acceptable to me than random crashes in software which cost me hundreds - or tens of thousands - or millions - of dollars.

    In order to increase some quality aspect of code (security, performance, robustness, correctness...) one can therefore focus on one or several categories - the people, the process, the culture, the tools, the technique, the time&cost etc. The choice of what to focus on is dictated by reality: no one has unlimited resources (except, almost, Google).

    There is no silver bullet - but there are golden rules. Finding people who know the difference is crucial I believe.

    (Full disclosure: Yeah, I'm looking for heavy duty PM work :)

    --
    They who would give up an essential liberty for temporary security, deserve neither liberty or security - Ben Franklin
  27. What do you think about... by hummassa · · Score: 1

    4) passing strings (or ANY data, for that matter) between separately-compiled, out-of-process components of your program ONLY via safe IPC marshalling mechanisms (like streams, files, pipes, etc...); keep in mind that the STL already has a mature marshalling-to-ASCII/UNICODE mechanism in

    --
    It's better to be the foot on the boot than the face on the pavement. ~~ tkx Kadin2048
    1. Re:What do you think about... by ojQj · · Score: 1

      Actually I was thinking about separately-compiled in-process components when writing the above. If you are otherwise in-process marshalling is kind of expensive. Out-of-process components is not an area in which I do much programming, so it sounds like you know more than me. Feel free to elaborate :o)

  28. As the saying goes by starmang · · Score: 0

    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

    --
    Never touch an Irish man's Guinness!@#
  29. In my opinion... by joxeanpiti · · Score: 1

    How do you go about making sure your code is secure?

    In my opinion the unique way is by trying to exploit/crash you program during development using logical and/or fuzzing techniques. Many programmers think that "security" is the last step they need to follow when writting a piece of software but they missed that security is one of the "intermediate" steps, not the last.

    In my case, I always conduct an audit in my software when a module (in example) is finished, when I added a new functionality, etc...

  30. Does language matter? by forgoil · · Score: 2, Interesting

    In this case it doesn't in one important way. Programming is the same regardless of language, since humans are the same regardless of language. What you need to write good software (again, why just secure? Why focus on a certain aspect, why not just generalize?) is skills/knowledge and good habits. My best advice here is to make sure you give yourself good coding habits. Don't say things like "I'll clean that up later" or "I will add error checks later" or something equally damaging. Give yourself good, sensible, habits and follow them. Any average programmer must know what buffer overflow means, and how to correct it. You can't even be an average programmer unless you know. So why is such insecure code written in C/C++ then? My thinking is plain mistakes and bad habits.

    1. Re:Does language matter? by RAMMS+EIN · · Score: 1

      ``Does language matter?''

      Yes, language matters. Although, as far as I know, it's possible to write secure code in every language and insecure code in every language, it matters a lot whether the language makes writing secure code easy or hard. If you scan a security list, you will see that the bulk of vulnerabilities are one of:

      1. Invalid memory access (e.g. buffer overflow)
      2. Injection (e.g. SQL injection, format string vulnerability, ...)
      3. Predictability (e.g. temporary filenames, TCP sequence numbers, ...)
      4. Information leak (e.g. storing a password in a world-readable file, failing to remove a temp file containing sensitive information, ...)

      Some of these classes can be completely ruled out by language features. For example, if you cannot manufacture and dereference your own pointers, you can never perform an invalid memory access. Others can be made easy to avoid by providing appropriate APIs, e.g. secure temporary file creation or constructs that ensure a created file is removed later.

      Many vulnerabilities occur in programs written in languages where the vulnerable code is easier to write than secure code. After all, why write

      baz = malloc(strlen(foo) + strlen(bar));
      sprintf(baz, "%s%s", foo, bar);

      if you could write

      (string-append foo bar)

      etc.

      --
      Please correct me if I got my facts wrong.
    2. Re:Does language matter? by The+Master+Control+P · · Score: 1

      baz = malloc(strlen(foo) + strlen(bar));
      sprintf(baz, "%s%s", foo, bar);


      Baz is one byte too short, which I assume is part of your point.

      Question though... I've read that memory allocation on most machines has to align along word boundaries, so if the end of an off-by-one overflow falls in the same word as the rest of the buffer, you're "OK" in the sense that it won't crash immediately. e.g. you malloc(30) on x86-32 and can technically write chars up to and including byte 32 without error, but b[32] will piss the memory manager off. If this is correct, then does the computer simply not care as long as you stay inside the word boundary, or does it actually allocate (bufsize + bufsize % wordlength?)

  31. Re:Don't use C++ as if it was only "C with classes by Delirium+Tremens · · Score: 1

    Developers can chose their employer.

  32. Absence of errors by Sique · · Score: 1

    You don't know your code is secure. You just know that it handles certain test cases apparently correct.

    (Ok... Silly examples like "while(TRUE);" are partially correct, because they never terminate, and thus you can't tell they handle the test cases incorrectly.)

    It's like scientific theories. You will never know if a scientific theory is entirely correct. You just can point to the test cases you have thrown at the theory which it was able to handle, and to the results you got from using the theory. It still doesn't prove that the theory is correct, only that you were unable to poke holes in it until now.

    So all you can do is check for known traps, border cases, predictable error conditions, and in general following the KISS principle to keep the number of test cases down. And keep all documentations for tests and checks you were doing as long as you are supporting the code.

    --
    .sig: Sique *sigh*
    1. Re:Absence of errors by gkhan1 · · Score: 1

      This is not strictly true. Scientific theories cannot be proven 100% true because they rely on inductive logic, throwing test cases at them as you say. However, programming is fundamentally a branch of mathematics (remember that every program in a Turing complete language is essentially just a Turing machine), and mathematics is not inductive, its deductive. From that you can, in fact, prove that it would be impossible for code to buffer overflow (given that the compiler, OS or hardware isn't malfunctioning, of course).

    2. Re:Absence of errors by Sique · · Score: 1

      To add a infinite regess:

      If you can't be sure you coded correctly in the first place, how can you be sure to at least write down the formal proof correctly?

      (And scientific theories don't need to rely on inductive logic, as Karl R. Popper pointed out.)

      --
      .sig: Sique *sigh*
    3. Re:Absence of errors by gtall · · Score: 1

      Not really, given any sufficiently powerful mathematics system, you can have true statements that are not provable. What people tend to forget is that similar reasoning will yield false statements that are not refutable. So, it is not the case that you can simply prove (or refute) all the properties you need to about any program.

      Gerry

    4. Re:Absence of errors by Anonymous Coward · · Score: 0

      Hey Sigue, I notice that your website contains pages that are obviously stolen from mine. I have worked very hard on those and I don't appreciate what you've done. Please remove them.

    5. Re:Absence of errors by Sique · · Score: 1

      If you look more closely on all the contents of http://127.0.0.1/ you will notice that all the stuff there can be somehow linked to you.

      --
      .sig: Sique *sigh*
    6. Re:Absence of errors by maxwell+demon · · Score: 1

      Not really, given any sufficiently powerful mathematics system, you can have true statements that are not provable. What people tend to forget is that similar reasoning will yield false statements that are not refutable. So, it is not the case that you can simply prove (or refute) all the properties you need to about any program.
       
      Gerry
        You don't need to apply that similar reasoning; you can directly derive the second claim from the first: If A is a true, but unprovable statement, then (not A) is a false but not refutable statement, because refuting (not A) means proving A.
      --
      The Tao of math: The numbers you can count are not the real numbers.
    7. Re:Absence of errors by Anonymous Coward · · Score: 0
      you will notice that all the stuff there can be somehow linked to you.

      How did you get all that stuff? Some of those pages can only be reached by knowing the file name. I admit it, you have skills. Now please please please remove my pages!

      I just did a simple test, and it looks like you are able to copy my new pages as I post them. So now I insist that you stop doing that or I will be forced to put up material that you will wish you didn't have.

    8. Re:Absence of errors by gkhan1 · · Score: 1

      People always bring up that damn incompleteness theorem! You have to remember that in 99% of all mathematics (including computer science), incompletness is pretty much irrelevant, virtually all theorems that mathematicians deal with are provably true or false. I know several people who have been mathematicians all their life and never even come across it (we all know it only because of GEB). So while strictly speaking you are correct, it is a very silly way to look at maths. Unless you're trying to write the halting program, you can be pretty sure that you can prove whether or not a program will overflow. If you can't, you can at the very least prove that it's not provable.

  33. Re:Don't use C++ as if it was only "C with classes by Viol8 · · Score: 2, Insightful

    Not necessarily , all I'm saying is that the STL can introduce bugs of its own that can be a lot harder to find than old style buffer overruns so its not a solution that will get rid of obscure coding (as opposed to logic) bugs.

  34. The only sure way I know of: Lambda calculus by Berkana · · Score: 4, Interesting

    If you program using strictly functional programming, you can not only verify that your code is 100% secure, but you can even automate the process. (Preferably in a functional programming language such as Scheme, caml, Haskel, LISP, or Erlang; imperative languages make it very difficult/slow to do with functions what functional languages do very naturally and easily.) Purely functional code can be subjected to automated code auditing easily, whereas code auditing imperative code cannot be guaranteed to catch every bug and unintentionally available abuse.

    Here's why, and why just about any computational problem can be solved using FP (functional programming):
    Functional languages conform to lambda calculus, which has been shown to be Turing equivalent, which means that any program that can be computed on a Turing machine can be solved using Lambda calculus. So long as you program using strictly functions, your program can be verified according to the rules of lambda calculus, and the verification would be as sure as a mathematical proof. This is the only sure way I know of really knowing with mathematical certainty that your application is secure.

    Pure functional programming has no assignment statements; there are no state changes for you to keep track of in your program, and in many cases abuses resulting unintended changes of state are the root of security problems. This is not to say that there is no state in functional programming; the state is maintained through function call parameters. (For example, in an imperative programming language, iteration loops keep track of a state variable that guides the running of the loop, whereas a functional program never actually keeps track of state with a variable that changes value; a functional program would carry out iteration by recursion, and the state is simply kept as a parameter passed to each call of the function. No variable with changing state is ever coded.)

    Since functional programs lack assignment statements, and assignment statements make up a large fraction of the code in imperative programs, functional programs tend to be a lot shorter for the same problem solved. (I can't give you a hard ratio, but depending on the problem, your code can be up to 90% shorter when described functionally.) Shorter code is easier to debug, which helps in securing code. The reason functional code is so much shorter is that functional programing describes the problem in terms of functions and composition of functions, whereas imperative code describes a step by step solution to the problem. Descriptions of problems in terms of functions tend to be far shorter than algorithmic descriptions of solving them, which is required in imperative code.

    Here's the biggest benefit of managing complexity with functional programming: as a coder, you NEVER have to worry about state being messed with. The outcome of each function is always the same so long as the function is called with the same parameters. In imperative programming as done in OOP, you can't depend on that. Unit testing each part doesn't guarantee that your code is bug free and secure because bugs can arise from the interaction of the parts even if every part is tested and passed. In functional programming, however, you never have to deal with that kind of problem because if you test that the range of each function is correct given the proper domain, and pre-screen the parameters being passed to each function to reject any out-of-domain parameters, you can know with certainty where your bugs come from by unit testing each function.

    If you need to guarantee the order of evaluation (something that critics of FP advocates sometimes use to dismiss FP advocacy), you can still use FP and benefit: in functional programming, order of evaluation can be enforced using monads. Explaining how is beyond the scope of a mere comment though, but in any case, if you need really reliable code, consider using a functional programming style.

    I can't do justice to the matter here; for more information, see th

    1. Re:The only sure way I know of: Lambda calculus by Sub+Zero+992 · · Score: 1, Insightful

      To be honest, I have got _no_ idea what you are trying to say.

      --
      They who would give up an essential liberty for temporary security, deserve neither liberty or security - Ben Franklin
    2. Re:The only sure way I know of: Lambda calculus by TheRaven64 · · Score: 4, Insightful
      When you start to introduce concurrency into a functional program, you end up with something closer to Pi calculus. The verification of both Pi and Lambda calculus expressions is still an open research problem (being worked on by some very bright people on the floor below me). There are a huge number of problems, not least of which in my mind is Gödel's incompleteness theorem, which states (roughly) that any system can only be completely described by a system more complicated than itself. You can generate a proof from your lambda program, but you still need to verify it and the proof will be more complicated (and thus harder to verify) than your original problem.

      There is also the question of what the proof actually says. You can't prove, for example, whether a lambda program will terminate (Halting Problem), and in fact you can prove that you can't prove this. If you have a sufficiently well expressed specification for your program, you can verify that the program and the specification match. Unfortunately, if you have a specification that concrete, you can just compile it and run it.

      By the way, Scheme is not a functional language. It has a number of properties that make it possible to write functional code, but saying Scheme is a functional language is like saying C++ is an object oriented language.

      --
      I am TheRaven on Soylent News
    3. Re:The only sure way I know of: Lambda calculus by Anonymous Coward · · Score: 2, Informative

      If you program using strictly functional programming, you can not only verify that your code is 100% secure, but you can even automate the process. You cannot write a program in a turing-complete language to determine if another program in a turing-complete language is 100% secure. It's trivially reducable to the halting problem. You can't automate it, at least not with 100% accuracy, in every case.

      Assume you have an algorithm (however complex) that can determine if a program in some turing complete language is secure, call it IsSecure(). IsSecure() is provably secure, because you've ran it on itself.

      Now, write a program that has a security hole if and only if IsSecure() returns true:

      #Program A
      start(input)
      {
              if(IsSecure(input))
                    ExposeSecurityHoleInSelf()
              else
                    #The hole must be in the function IsSecure(), which is silly, because you've used IsSecure() to secure IsSecure()
      }


      Call program A passing itself as input.
      Q.E.D.

    4. Re:The only sure way I know of: Lambda calculus by gtall · · Score: 1

      In particular, reflection in Scheme is enough to break functionality.

      Gerry

    5. Re:The only sure way I know of: Lambda calculus by Anonymous Coward · · Score: 1, Informative
      I love functional programming, I'm not bashing it, but it's not enough.


      If you know lambda calculus then you also know The Halting Problem. There are an entire set of exploits based up on it. Real ones, they don't generally lead to data compromise but they negatively impact performance and hide other things. Snort for example allows for regular expressions to be used in signatures, likewise there are pathological datasets that cause snort to spend 10s of thousands times more time processing regexes than initially expected. There are signatures that have datasets that can cause a modern machine to spends minutes processing regexes, while real hacker data is passing through unseen. It's a classical halting problem example


      FP is about algorithm correctness.


      Another problem is that programs are attacked at their touch points to the world, users and other program. FP nicely ignores those problems as side effects and doesn't have a clearly definied lambda calculus for dealing with them.


      I definitely thing FP solves some set of problems and should be used more but it won't make anything more secure any time soon.

    6. Re:The only sure way I know of: Lambda calculus by asuffield · · Score: 2, Informative
      You cannot write a program in a turing-complete language to determine if another program in a turing-complete language is 100% secure. It's trivially reducable to the halting problem. You can't automate it, at least not with 100% accuracy, in every case.


      Congratulations, you have won today's "Ignorant undergraduate misunderstanding of the Halting problem" prize.

      You're wrong on every significant point. You can write a program in a turing-complete language to determine if another program in a turing-complete language is 100% secure. The way that you specified implementing such a program is flawed. The Halting problem says that there exist certain ways to specify a problem which admit no solution, even though a solution to the problem exists. It does not say that there exist no alternative ways to specify the problem which do admit solutions. People always seem to think that the purpose of the Halting proof was to demonstrate that the real-world problem couldn't be solved - this is wrong. The purpose of the proof was merely to demonstrate that there exist certain non-trivial, interesting mathematical problem specifications which don't have solutions. This has interesting results in computability theory. It has very little relevance to the question of what sort of software we can write. It's all about how you reduce the real-world problem into a mathematical problem specification.

      Assume you have an algorithm (however complex) that can determine if a program in some turing complete language is secure, call it IsSecure(). IsSecure() is provably secure, because you've ran it on itself.

      Now, write a program that has a security hole if and only if IsSecure() returns true:

      #Program A
      start(input)
      {
                      if(IsSecure(input))
                                  ExposeSecurityHoleInSelf()
                      else
                                  #The hole must be in the function IsSecure(), which is silly, because you've used IsSecure() to secure IsSecure()
      }


      IsSecure returns false when passed this program as input. It doesn't matter that you think the answer is silly. This program is not secure because there exists a call to ExposeSecurityHoleInSelf in it and IsSecure failed to prove that this call was unreachable, or just didn't give a damn that it was unreachable. That is defined as an insecure program for the purpose of the IsSecure function. By specifying the problem in this way, we admit the possibility of a solution, and the Halting problem is avoided.

      In most cases, the Halting problem can be avoided in this manner. Nothing compels you to define your program as having no false positives.
      For the purposes of automated security validation, false positives are not a serious problem - we can easily write the program in a manner that can be proven secure by a given prover. We don't have to accept arbitrary programs as input.

      In practice, we don't do it like this. The function we use in the real world is is_proof_of_security_valid(), and it takes two inputs - a program and a proof of the program's security. The function checks that the proof is valid for this program. The proof itself is generated semi-automatically, but some parts are supplied by humans - typically via markup in the program's source (lint tags are a classic example of this sort of thing). It's much easier to write the thing this way.
    7. Re:The only sure way I know of: Lambda calculus by asuffield · · Score: 1

      You're stuck in the 1970s. Lambda calculus is an old formalism. It has some interesting applications, but it's still fundamentally old. We have better methods now. Operational semantics and its variations are the main ones here. They're far more powerful systems than the lambda calculus, and they work just fine for imperative languages, proving the same sort of things. You don't have to stick to any particular rules. All known features of modern real-world languages have been modelled sufficiently in at least one variation of operational semantics (the different variations deal with things like non-trivial type systems, which need special treatment - it's really tricky to prove things about a C++ template class, but it's doable if you use a sufficiently powerful formalism).

      There are some interesting advantages to pure functional languages, but this is not one of them. It's just that back in the 1970s, the problem of how to do it for non-functional languages hadn't been solved yet. Nowadays, it has been solved - so you can stick with easy languages like C and INTERCAL, and don't have to deal with lisp variants.

    8. Re:The only sure way I know of: Lambda calculus by Anonymous Coward · · Score: 0

      OMG. Someone knowing something about program theory on / !

      What is that ? 1998 again ?

    9. Re:The only sure way I know of: Lambda calculus by SheeEttin · · Score: 2, Funny
      You can't prove, for example, whether a lambda program will terminate (Halting Problem)
      If you're running Windows, no problem. It'll terminate within the first few hours.
    10. Re:The only sure way I know of: Lambda calculus by Coryoth · · Score: 2, Informative
      There are a few misconceptions here which deserve comment.

      You can't prove, for example, whether a lambda program will terminate (Halting Problem), and in fact you can prove that you can't prove this.

      This simply isn't the case - there are lots of programs for which you can easily prove termination. The catch with the Halting problem is that you cannot find a procedure that will work for all programs. In other words you may find yourself in a situation where you cannot prove termination for certain programs; that does not mean, however, that you can't prove termination for others, nor that such proofs are invalid. Trying to prove termination is far from futile - the Halting problem will at worst tell you that you might not be able to do it, but if you can (and often enough you can indeed) then the proof is perfectly valid.

      If you have a sufficiently well expressed specification for your program, you can verify that the program and the specification match. Unfortunately, if you have a specification that concrete, you can just compile it and run it.

      Again, this isn't quite true. Certainly, for some problems, an accurate specification will be equivalent in complexity to an implementation. On the other hand, there are a great many problems where that isn't the case. Take a specification for finding a square root (to within a specified error tolerance epsilon): given an input number x, the function must produce a value y such that abs(x - y*y) < epsilon. That's a complete specification (and it isn't hard to formalise that into a suitable specification language) but you certainly can't compile and run it and get anything useful - the actual implementation of how to find the square root is going to be more detailed, and quite important.

      Similarly we can specificy a sort function: given a list of items (comparable by '<') the function must return a list that is a permutation of the input list (that is, they contain the same elements), and such that for each list index i (except the index of the last element) result[i] < result[i+1]. Again, that's a complete specification for a sort function - it ensures that the function does indeed sort the list. On the other hand it is not compilable (except, maybe, into bogosort), and any particular sort implementation will have to use a specific sorting algorithm (be it quicksort, mergesort, or otherwise) which will be undoubtedly more complex than the simple specification given.
    11. Re:The only sure way I know of: Lambda calculus by RAMMS+EIN · · Score: 1

      A couple of points:

      1. If you can prove that a functional program is secure, you can also prove an imperative program is secure by first converting it to a functional one (at least, I think one can always convert an imperative program into a functional one).

      2. I don't think you can determine, in general, that a program is secure. What if it depends on the halting problem? How do you prove that a program does not contain vulnerabilities of classes you are not aware of?

      3. No program lives in isolation. Even if you've managed to prove that your program is secure, perhaps a flaw in its environment (interpreter, operating system, hardware, ...) causes a vulnerability. This would, of course, not be your program's fault, but your program would be affected.

      --
      Please correct me if I got my facts wrong.
    12. Re:The only sure way I know of: Lambda calculus by marcosdumay · · Score: 1

      "Similarly we can specificy a sort function: given a list of items (comparable by '

      It is compilable, and will create a bubblesort if you try it with prolog. But almost no real world programs can be specified that way.

    13. Re:The only sure way I know of: Lambda calculus by dkoulomzin · · Score: 1

      1. Absolutely, assuming both languages are Turing Complete
      2. How in general? If you mean "for all turing machine programs" or something, then yes, there is a reduction to the halting problem (though not the one given above, that's just terrible). But if you mean "all programs that can run on my T-42 IBM laptop", then no. This is because there are a finite number of states that my laptop can be in, and therefore the set of all programs that can run on it is NOT Turing complete. So there IS in fact a program that can determine whether a certain program that I'm about to run on my machine will halt on a given input. The program is simple: you count the total number of states the machine could enter, and then you run the program on a machine simulator for exactly that many "cycles." If it hasn't halted by then, it won't. Proof by counting: if you continue to run the program, then there is some state you have entered twice, meaning there is a loop which will cause the program to run forever.
      3. True.

      --
      Thou shalt not begin a subject line or post with the word "Umm".
    14. Re:The only sure way I know of: Lambda calculus by RAMMS+EIN · · Score: 1

      ``But if you mean "all programs that can run on my T-42 IBM laptop", then no. This is because there are a finite number of states that my laptop can be in, and therefore the set of all programs that can run on it is NOT Turing complete. So there IS in fact a program that can determine whether a certain program that I'm about to run on my machine will halt on a given input. The program is simple: you count the total number of states the machine could enter, and then you run the program on a machine simulator for exactly that many "cycles." If it hasn't halted by then, it won't. Proof by counting: if you continue to run the program, then there is some state you have entered twice, meaning there is a loop which will cause the program to run forever.''

      I think you're right in saying this algorithm will tell you if a given program will halt on your Thinkpad. However, I don't want to prove things about a program, given that it is run on your Thinkpad; I want to prove things about a program that hold for any correct implementation of the semantics of the language the program is in.

      --
      Please correct me if I got my facts wrong.
    15. Re:The only sure way I know of: Lambda calculus by Procyon101 · · Score: 1

      Brilliant!

      You had to give it away with Intercal though, didn't you...

    16. Re:The only sure way I know of: Lambda calculus by Coryoth · · Score: 1

      Compilable in a very broad sense, and not of any real practical value (that prolog is kind enough to assume bubblesort as opposed to bogosort is just icing). The reality is that the specification is far shorter than any decent implementation. As to whether much real world code can be specified this way: try actually looking at code written with specifications such as SPARK-Ada code, JML annotated Java, or Eiffel. A surprising amount of real world code can, if you're actually willing to try, be specified efficiently. Sure, some things, like printing output, or GUIs, don't lend themselves to specification - that doesn't mean that there aren't lots of things that do however.

    17. Re:The only sure way I know of: Lambda calculus by oblivion95 · · Score: 1

      Thanks. I was having trouble following his "proof".

      I hope someone mods this up.

    18. Re:The only sure way I know of: Lambda calculus by NittanyTuring · · Score: 1

      So long as you program using strictly functions, your program can be verified according to the rules of lambda calculus, and the verification would be as sure as a mathematical proof. This is the only sure way I know of really knowing with mathematical certainty that your application is secure. Rice's theorem. Proving any non-trivial property about functional programs is undecidable.

      Here's a simple example: the halting problem. Just try to prove that your functional program will terminate. You can't do it! If you don't know that your daemons will terminate, an attacker can potentially make them non-terminating (e.g. an infinite loop). This definitely constitutes a security hole: it's a DoS attack.

      There is a large body of work on program proving, and it certainly isn't bound to lambda calculus or even functional programming. Your intentions are appreciated, but come on, your understanding is basic. Take another class or two if you want to really know what's going on here... or learn something you can use today.
    19. Re:The only sure way I know of: Lambda calculus by Solitonic · · Score: 1
      Congratulations, you have won today's "Ignorant undergraduate misunderstanding of the Halting problem" prize.

      Man, it's annoying when someone accuses another of ignorance when the former is more wrong by an order of magnitude!

      The parent poster wrote

      You cannot write a program in a turing-complete language to determine if another program in a turing-complete language is 100% secure. It's trivially reducable to the halting problem. You can't automate it, at least not with 100% accuracy, in every case.

      and that assertion stands as claimed.

      He is arguing that there is no such (secure) algorithm which always answers (correctly) in every case (100% accuracy). His argument is perfectly fine: it's a routine and trivial application of Cantor's diagonalization method. If you really disagree, I challenge you to produce such an algorithm forthwith.

      Your problem is that you have misunderstood the hypotheses in his proof sketch and tried to replace a universal quantifier with an existential one. Of course there is some limited program that can verify the security of some carefully specified others.

      IsSecure() cannot return false when passed program A as input without violating the hypotheses.

      Your changing the specification of the problem is analogous to removing the "not" in "This sentence is not true." and then claiming: Wow, no contradiction!

      You're wrong on almost every significant point.

      Indeed.
    20. Re:The only sure way I know of: Lambda calculus by Anonymous Coward · · Score: 0
      He is arguing that there is no such (secure) algorithm which always answers (correctly) in every case (100% accuracy). His argument is perfectly fine: it's a routine and trivial application of Cantor's diagonalization method.


      And completely, utterly irrelevant to the issue at hand. You also appear to be failing to grasp the notion of a real world in which actual problems exist, instead of thought-experiments.

      If you really disagree, I challenge you to produce such an algorithm forthwith.


      splint. The whole point is that the article is about things like this, and not about mental masturbation.

      Your changing the specification of the problem is analogous to removing the "not" in "This sentence is not true." and then claiming: Wow, no contradiction!


      No, it's more like taking the statement "Make a building. But make it out of cheese - see, you can't, it's impossible to make buildings", saying "don't be a prat", and deleting the second sentence.

      Don't invent problems that don't exist in the real world.
    21. Re:The only sure way I know of: Lambda calculus by Solitonic · · Score: 1

      Irrelevant to the real world? Hmmm... I suppose one's definition of "real" depends on the limitations of one's experience, but a clearer understanding of what is and is not possible in principle should surely be recognized as relevant by anyone interested. Maybe you really just aren't. Studies of intractability in computability do not only show where the boundaries lie, but can be helpful and save time in practical ways. In the context of security, I've personally seen halting concerns arise in turing-complete grammar extensions to regular expression engines, for example. Ever heard of a DoS attack? You wouldn't want a devious user to trigger one of those on your modded PCRE engine, so what's the best prefilter/dectector? Doh! There isn't one! Good thing that expensive CS education helped to steer us clear of that pitfall. Why aren't there any good sendmail configuration security checkers? Answer. Honestly, there are an infinitude of real, practical examples. You need to check out Garey&Johnson's Classic, at least the introduction. :-)

      uh... splint? Now you're just being silly on purpose.

      Make it out of cheese? Talk about an irrelevancy.

      Poor Russell and Gödel and Turing and Post and Church and Rice and .... All those mental masturbators! What wasted lives!

    22. Re:The only sure way I know of: Lambda calculus by cpeikert · · Score: 1

      Functional languages conform to lambda calculus, which has been shown to be Turing equivalent, which means that any program that can be computed on a Turing machine can be solved using Lambda calculus.

      And for this reason, checking correctness of code cannot be automated, for that would solve the Halting Problem.

      Not that functional programming isn't great. You're just overselling it.

  35. Security? What's that? by JHWH · · Score: 2, Insightful

    You can write code that can be as secure as you want, but what about libraries, compilers and hardware?
    I think the question itself makes little sense without a deeper investigation in the system!

    --
    Intelligence has limits. Stupidity doesn't.
  36. buffer overruns should be easy, at least? by Mirar · · Score: 1

    Avoiding buffer overruns should be fairly easy, anyway, shouldn't it? Don't used fixed size buffers, unless you really have a control of what's going in them. And if you do, don't place them on the stack.

    Now the *other* security flaws... ...but I agree with previous speakers. Open your source, let the world check it. If you don't, chances are someone will disassemble it and find the flaws anyway, but wont tell you.

    1. Re:buffer overruns should be easy, at least? by iggymanz · · Score: 1

      variable sized buffers have even more opportunity for errors and make more ways a program can fail (the problem of potential buffer overflow remains, and now you can have memory leaks, for starters).

  37. Port it to Visual Basic by Anonymous Coward · · Score: 0

    just port your proggy to Visual Basic and you'll be fine ;)

  38. Re:Don't use C++ as if it was only "C with classes by quigonn · · Score: 1

    But the number of employers where you actually get a chance to use languages like Eiffel, Ada, Dylan, ... is very small.

    --
    A monkey is doing the real work for me.
  39. my 2 cents by Anonymous Coward · · Score: 0

    Every function handling alien data should be foulprof. Double check it, let someoneelse double check it. After the incomming data has been verified as correct.. then.. well.. dont care to much, just make sure the logic of the program works. The important thing is after all that no one else can break your program, less important if you can.. If you do you will surely see it in the tests.. But always, always verify all input data the program has. If it doesn't fit what the program exspected, complain and reject or even exit(-1). Never Ever process data in your program you dont have control of.

  40. By the way, I meant to say this also by Berkana · · Score: 3, Interesting
    If you want to learn about Lambda Calculus (which was developed by Alonzo Church, a contemporary of Allan Turing), Wikipedia is a good place to start (http://en.wikipedia.org/wiki/Lambda_calculus ), but mastering Lambda Calculus is not necessary; first master a functional programming language, and a lot of the lambda calculus will be made easier.

    To summarize, here's how you verify with mathematical certainty that a functional program is secure:
    1. You use purely functional code; that guarantees that there are no changes of state involved in the operation of your program.
    2. you unit test each function to make sure that given the correct domain/scope, their return values are always conforming to the desired range (and I don't just mean numbers when I say "range"; I mean correct data formatting, list/tree formatting, data structures, etc.), and you set up input filters that exclude any call parameters that are not part of your desired function domain.
    3. You check to see what functions call which functions, and make sure that they never call a function with parameters that are incorrectly formatted or out of the correct domain
    4. You make sure that every function and every constant is properly scoped.

    That's the gist of it. Anything more on this topic, such as automatic code auditing with the certainty of mathematical proofs (by means of lambda calculus proofs) is beyond my expertise. I just know that it's possible to truly secure functional code with mathematical certainty, whereas with imperative code, you can only be sure that your code has not yet failed or exposed a rare bug or failure condition.
  41. Re:Don't use C++ as if it was only "C with classes by shutdown+-p+now · · Score: 3, Informative
    Uh... let's see. Open the most recent ISO C++ standard, and search for all occurences of "undefined". Repeat for "implementation-defined". Make a notice of how many of those are from the sections related to the Standard Library. Then meditate on the results.

    Yes, sure, if you use STL, you need not worry about getting the buffer size wrong. And that's about it - container indexing is not bound-checked (unless you use at() instead of operator[] - and that's about the only instance of run-time safety check I remember seeing in STL!), iterators can go outside their container without notice, or can suddenly become invalid depending on what their container is and what was done to it. Even leaving library issues aside, there are some nasty things about the language itself - it's just way too easy to get an uninitialized variable or a class member, or to mess up with the order of field initializers in constructor.

    This is not to say that C++ is not a good language. All of the above are features in a sense they are there for a reason - but they certainly don't make writing secure software easier.

  42. 3 Things by Anonymous Coward · · Score: 1, Interesting

    a) good coding practices
    b) formal peer reviews for pre-design, design, code, test specifications, and test results
    c) Purify!!! http://www-306.ibm.com/software/awdtools/purify/ A license for every developer AND tester!

    I haven't written any code since 1999, but that was how I setup the development team for that company. The reviews also are a form of cross training and team building. Nobody is perfect and showing our individual errors helps everyone fit in. OTOH, there was 1 guy who clearly didn't understand header files and was labled "Mr. Header" for almost a year. After the first 1 week of taunts by his peers, he quickly learned when and how to avoid putting too many header files into his code.

    Other code issues were discovered and learned by the entire team. We didn't hide errors, we published them within the team and never told management anything about who caused what to happen.

  43. Coding 101 by Tom · · Score: 4, Insightful

    We all know the answer if we've studied computer science. The problem is that the answer is boring, lots of work and totally non-hip.

    It's specifications, pre- and post-conditions, all that "theoretical bullshit" we learned in university. It's just that writing code that way is very un-exciting, and that's a vast understatement.

    --
    Assorted stuff I do sometimes: Lemuria.org
    1. Re:Coding 101 by Coryoth · · Score: 2, Insightful
      It's specifications, pre- and post-conditions, all that "theoretical bullshit" we learned in university. It's just that writing code that way is very un-exciting, and that's a vast understatement.

      That depends really. As a math geek I find a certain amount of pedantry and formlisation natural. I mean many people are happy to spend the extra time writing annotations to define types signatures for functions (and even types for variables in some languages) which is, really, just a light form of specification. Using Eiffel, or Java with JML, or Spec#, or D, really isn't as bad as you might think - you mostly end up writing things you'll have to get around to writing anyway (when it comes time to properly document APIs etc.), you just get to write it along with the code in a slightly more formal way...
    2. Re:Coding 101 by RAMMS+EIN · · Score: 1

      Specifications won't help you, because the attacker is not going to stick to them.

      --
      Please correct me if I got my facts wrong.
    3. Re:Coding 101 by laffer1 · · Score: 1

      Specifications help you determine what correct and incorrect input are. This allows you to write proper test cases. Testing leads to bug fixing. Bug fixing leads to anger. Anger leads to hate. Hate leads to a new PC when I pitch mine out the window.

      In short, you should try to write proper specifications for important projects. It can also lead to hardware upgrades.

      As an example what not to do, look at the source code for JustJournal.com's Users servlet (com.justjournal.Users). It is the worst code I've ever written. I did not create any specifications, do any design or any planning. Yet its still in use almost 4 years later. You never know what will happen with your code. I'm too lazy to rewrite it.

    4. Re:Coding 101 by Anonymous Coward · · Score: 0

      If your API enforces the specifications, the attacker has no choice.

    5. Re:Coding 101 by Tom · · Score: 1

      They're for the coders, not the attackers.

      A proper specification with testable pre- and post-conditions allows you to eliminate most input variable problems and a host of others.

      --
      Assorted stuff I do sometimes: Lemuria.org
  44. old versions of purify by joss · · Score: 2, Interesting

    Helped a lot for this kind of thing. The tool went downhill quite
    a long way but its still useful. Electric fence helps too.
    Then a lot of old fashioned software engineering.. use raw arrays
    as little as possible, add bounds checking to std::vector [] if you
    feel inclined, use gprof to identify any code not being excercised
    by your unit tests [you do have unit tests, right]. Lastly, actually
    read the darn code and make sure anytime you are using raw arrays
    you check the size.

    --
    http://rareformnewmedia.com/
  45. Half a solution by DoofusOfDeath · · Score: 3, Funny
    How Do You Know Your Code is Secure?

    Make it part of the critical path in music DRM. Then you know it's not secure.

    Not sure about the flip-side, though.

  46. Re:Don't use C++ as if it was only "C with classes by orangeyoda · · Score: 2, Funny

    Which is a good thing, Ada was awful to learn and worse to debug. I've seen the light, no more c++ spending hours to decode meglomaniac's tempalates , no more java exception hell , bye bye vb6 error unhandling . Hello C#

  47. If it compiles... by GroovBird · · Score: 2, Funny

    ...you can ship it.

    It's that simple!

  48. Is it all about buffer overflows ?! by neurorebel · · Score: 1

    How about user/password management ? No matter how your shiny GC collects the garbage you create on memory... You still have the opportunity to make a mess out of faulty authentication schemes or stupid array usage... Besides even though your code is secure, the environment on which it runs may be configured/set up/run by a stupid administrator with all those bullshit certificates in his back. Does it sound familiar ??

  49. Correct but irrelevant by Anonymous Coward · · Score: 0

    All the above statements on the power and elegance of FP are true, but totally unrelated to how programs are actually cracked.

    The essence of cracking an application today is to break the semantics of the computational model. Once the attacker breaks that, end of story. This is the common denominator of buffer overflows, memory allocation exploits, TOCTTOU attacks, etc.

    1. Re:Correct but irrelevant by Anonymous Coward · · Score: 0

      The essence of cracking an application today is to break the semantics of the computational model. Once the attacker breaks that, end of story.

      Good luck trying to break the semantics of the computational model of a purely functional program. The same mechanism that guarantees that every function invocation is referentially transparent also guarantees that there are no possible hooks for alternative semantics.

    2. Re:Correct but irrelevant by tepples · · Score: 1

      Good luck trying to break the semantics of the computational model of a purely functional program.

      In what manner does pure functional programming handle interactive input and output and database access, all of which have inherent state?

    3. Re:Correct but irrelevant by Berkana · · Score: 2, Interesting

      They handle state in a scoped manner that is hard to describe without lots of example code. The best example I can think of is Erlang. If you look at the link I posted above (re-posted for your convenience: http://www.defmacro.org/ramblings/fp.html ) they mention Ericsson inventing the functional language Erlang to handle concurrency.

      As for how state functional languages handle state; state is held in the parameters a function is called with. The simplest example is recursion; in an imperative program using a for loop or a while loop or something like that, state is stored in a counter variable that gets incremented or decremented or somehow changed each time the loop is run. In recursion, if the ending condition is not met, the function calls itself with slightly differing parameters; the parameters keep track of the state, but unlike imperative programming, since the parameter is not a variable that can be changed once a call is made, it is impossible to have bugs caused by unexpected or unintentional changes to a variable in the scope of other operations that might change it. FP doesn't permit any declared values to change, so there are no "variables", just constants.

      If this makes no sense at all, you'll just have to program a few loops in an imperative language, and a few in a functional language using recursion, and see the difference. It's a lot easier to show interactively than to explain.

  50. Meh by Rob+T+Firefly · · Score: 1

    Who needs security? Thanks to the DMCA, all I have to do is keep my code proprietary. Then it's illegal for people to hax my code, so it won't happen!

  51. SPARK by Rod+Chapman · · Score: 5, Insightful

    For high-integrity stuff, we use SPARK (http://www.sparkada.com/) - a design-by-contract subset of Ada95 that is entirely designed-from-scratch for verification purposes.
    The verification system implements Hoare-logic and is supported by a theorem prover. Buffer Overflow is only one of many basic correctness properties that can be verified. Properties that can be verified are only limited to what can be expressed as an assertion in first-order logic.
    SPARK is a small language (compared to C++ or Java...) but the depth and soundness of verification is unmatched by anything like FindBugs, SPLINT, ESC/Java or any of the other tools for the "popular" languages.
    (If you don't know or care what soundness is in the context of static analysis, then you've probably missed the point of this post... :-) )
    - Rod Chapman, Praxis

    1. Re:SPARK by marcosdumay · · Score: 1

      "SPARK is a small language (compared to C++ or Java...)"

      Isn't that a feature?

    2. Re:SPARK by Jerry+Coffin · · Score: 1
      ...a design-by-contract subset of Ada95 that is entirely designed-from-scratch for verification purposes.

      To be true, it would appear that SPARK would have to have been designed sometime before Ada83, and then the other parts of Ada added on afterwards. I don't believe that's the case.

      --
      The universe is a figment of its own imagination.
  52. misspellings by capoccia · · Score: 1
    "Marucs Ranum notes taht 'It's really hard to tell the difference between a program that works and one that just appears to work.'
    it's hard to tell the difference between being human, and appearing to be human... oh, wait -- there's a misspelling. i think he's real... or maybe just a robot with bad programming.
  53. Memories of a pizza hack. by TapeCutter · · Score: 1

    "Code writting is not pizza baking."

    Reminds me of the time when "someone" hacked our new fangled photocopier to complain it was "out of pizza" rather than paper.

    --
    And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
  54. typos by thegnu · · Score: 0, Offtopic

    Marucs Ranum notes taht...

    I'm not one to orthography-Nazi up a place, but how are we going to fool the noobs into thinking we're better than them with editors overlooking such blatant typos as the above?

    --
    Please stop stalking me, bro.
  55. That does stop pwning, though. by Oddscurity · · Score: 1

    You may be on to something here. Once your box is a pile of smoking rubble from all that trashing, *nobody* will be able to pwn it.

    --
    Indeed!
    1. Re:That does stop pwning, though. by et764 · · Score: 1

      You may be on to something here. Once your box is a pile of smoking rubble from all that trashing, *nobody* will be able to pwn it.

      That must be why Vista is the most secure version of Windows ever. I swear the hard drive LED is lit more often than the power LED.

  56. Consider the Unthinkable... by duh_lime · · Score: 1
    That someone will come up with a use for your code that you did not envision - Or use it in a way that you did not envision.

    Secure Code is not just about the microcosm of a "routine" or "method", but rather of the entire ecosystem of a collection of code. Don't just look at the security problem through a straw, looking for buffer overflows and the like. You need to find those too, but that's just the tip of the iceberg.

  57. Re:Don't use C++ as if it was only "C with classes by DeKO · · Score: 1

    But let's not forget that when an iterator "go outside their container" you already have a serious logic error. The same logic error can be even more catastrophic in other languages that do run-time checking to avoid crashing, and allow you to do something like "on error resume next". BTW, you are allowed to derivate from standard containers and create checked operations (like operator[] that maps to at()).

    Other languages have novel approaches to solve C++ problems, but nothing can stop logic errors, wrong algorithms, bad programmers, etc.

  58. Its all about risk... by s31523 · · Score: 1

    As another post pointed out, we all know the answer... Testing and writing code according the best practices documented by so many books. For commercially developed software "code security" is something that is usually addressed based on the perceived risk of a vulnerability. Risk can be quantified by the probability of an event multiplied by danger the event poses. In a commercially developed piece of software schedule and cost drive a program so the developers know the code is not secure and the managers use risk analysis to find the "biggest" holes. Usually too much time is spent in development before testing is considered so you end up with a "lets fix the major problems and ship it". No code is totally secure, but if you demand secure code, you better deploy lots of automated unit/white box or black box tests to mitigate the risk.

  59. You know you're a geek when... by ruiner13 · · Score: 4, Funny
    You say things like:

    Mistakes will come back to byte you. without even flinching.
    --

    today is spelling optional day.

  60. Re:Don't use C++ as if it was only "C with classes by Anonymous Coward · · Score: 1, Interesting
    I don't know that I'd say the STL helps you a lot in this way. It's great, though, I like it a lot. Buffer overflows and stack overflows are side-effects of memory management. If you don't want to or cannot manage memory, or aren't sure, then you really want to do your project in Java or OCaml or something else. That's the issue.


    C and C++ coders have jammed allocated memory on to the stack for years to make it "garbage collected" when the frame pops off the stack. That also opens up the very easy to exploit stack overflows, if you put memory on the stack and then do any unbounded or improperly bounded I/O to it, you're done. The STL provides smart pointers to allow you to manage heap as if it were on the stack but the problem remains that you have to manage it.


    The word on the street, and I discount it, by a lot of the hackery types is that the use of C++ with any overflow is easier to exploit than a normal C application because it has the virtual function look up table which basically provides an easy one-stop shop where you can get a pointer to almost any other subroutine in the program. It makes sense logically but I don't know of any exploits that make use of it

  61. Re:Don't use C++ as if it was only "C with classes by Blakey+Rat · · Score: 1

    And automobiles can introduce problems (air pollution) that didn't previously exist with the form of transportation they replaced. But I think we all agree that a little bit of air pollution is better than thousands of people a day being trampled by horses in city streets.

  62. binary compatability caveats by Anonymous Coward · · Score: 0

    You also have the ability to use a plugin architecture, such as XPCOM, for the binary compatability issues.

  63. Re:Don't use C++ as if it was only "C with classes by Metasquares · · Score: 3, Interesting

    Once you go outside of a container, you already have a fatal error and the appropriate response is to crash (albeit gracefully if possible). The problem isn't so much that the program crashes, but rather that the program may consider data outside of bounds as valid memory, thus allowing buffer overflows and undefined behavior to occur.

    The difference between pure C/C++ and the STL is that something like strcmp can create a rather subtle sort of buffer overflow error, whereas buffer overflows involving STL containers are generally easier to avoid and detect. For that matter, if you use the STL algorithms library to its full potential, you may find that you hardly ever need to use explicit indexing or iterators other than begin() and end().

  64. There are no good open source tools, unfortunately by Random+Walk · · Score: 2, Informative
    Although many (if not most) open-souce apps are written in C/C++, there are no really useful open source tools to check C/C++ code for security:
    • valgrind is very nice, but only reports memory corruption if it really occurs (i.e. you have to trigger the bug first). Not very useful to detect bugs.
    • splint doesn't understand the flow of control, thus it needs tons of annotations to work properly. A royal PITA if you work on existing code. Also, it just shifts the problem: how do you now prove that your annotations are correct? Besides, it produces tons of spurious warnings.
    • flawfinder, rats, et. al. just grep the code for suspicious functions like strcpy(). They don't understand C/C++, and thus produce warnings even in cases where it's perfectly clear that these functions are used safely.
    • some academic projects (like e.g. uno, ccured, ...) look interesting, but usually don't work on nontrivial code (at least not unless you are part of the development team and know the required wizardry to make them work). Also, most acedemic project go into limbo as soon as the thesis is written.
    I think one of the major problems is that commercial vendors like e.g. Coverity offer free service at least to major open-source projects, thus stifling any initiative to produce open-source counterparts of such tools.
  65. Re:Don't use C++ as if it was only "C with classes by mrchaotica · · Score: 1

    If you want flexibility and usefulness, why not skip C++ and go straight to Java or C#?

    --

    "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

  66. Re:Don't use C++ as if it was only "C with classes by Anonymous Coward · · Score: 2, Insightful

    TFA: "Especially if you have to write in a language like C or C++?"

    Why would you HAVE to use C or C+ or C*+**+++? I don't mean to be a troll, but if you are writing in an inherently insecure language (i.e., any compiled language) you aren't going to get secure code.

    OTOH of you write in, say, assembly, you are setting yourself up for the complexity. You have to make sure your buffers won't overflow, as opposed to leaving it to the compiler writers.

    As to overflows, if you KNOW your language is prone to overflowed buffers, it seems wise to check for overflows with your own code. After this long, there really is no excuse for buffers that overflow. It isn't hard to check for the length of a string, after all.

    If bridge engineers were as lazy as programmers, bridges would be falling down by the hundreds. My 1992 car is full of hundreds of thousands little bitty moving partsand fluids, but as long as I keep clean oil and filters in it, it doesn't break. My last car was an 1988, it lasted until last year. But I have to replace my 2002 Microsoft operating system because it's not secure? Somebody is making a lot of money off of poorly designed and poorly built software. There is no reason why I should have rto replace an OS.

    There are reasons for program errors, but no excuses. If your code is shit, it's shit because you wrote shit. Either you're incompetent or lazy. "You can have cheap, secure, or fast. Pick two."

  67. Re:Don't use C++ as if it was only "C with classes by swillden · · Score: 4, Informative

    whereas in a highly abstracted C++ program using the STL with lots of objects being copied and references flying around it can be a LOT harder to figure out whats really going on , especially since different compilers do different things under the hood.

    Those bugs aren't harder to track down than "old-style" bugs, in fact I think they're vastly easier to track down than, say, a wild pointer. The difference is that you're less experienced at dealing with the new problems, so they seem harder to you. With time and practice, you'll see through copy/reference errors quickly. In the meantime, a little discipline can cover your lack of experience -- never store raw pointers in collections, always "objects". If you don't want to create copies, then store objects of a smart pointer class. In fact, avoid ever using raw pointers at all. *Always* assign the result of a 'new' operation to a smart pointer (auto_ptr works for a surprisingly large set of cases, but you may have to get a reference counted pointer type or similar for others -- the BOOST library has some good options if you haven't already rolled your own).

    If you really run into different behavior with different compilers, then at least one of the compilers is buggy. That does happen, but it's a lot rarer today than it was a few years ago. When you find that situation, wrap the tricky bit behind another abstraction layer and implement compiler-specific workarounds so that your application code can just use the abstraction and get consistent behavior. In most cases, someone else has already done this work for you. Again, look into BOOST.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  68. Re:Don't use C++ as if it was only "C with classes by Anonymous Coward · · Score: 0
    But I think we all agree that a little bit of air pollution is better than thousands of people a day being trampled by horses in city streets.

    And thousands of people a day don't get hit by cars in city streets now?

  69. Re:There are no good open source tools, unfortunat by Shrubber · · Score: 1
    I think one of the major problems is that commercial vendors like e.g. Coverity offer free service at least to major open-source projects
    And even when they don't offer free service, they get free advertising on slashdot.
    It was an interesting article and I agree with almost everything the author said, but it was also a multipage advertisement for a commercial application directly hitting the target demographic.

    That's hard to buy, and Fortify got it free!
  70. But... by hummassa · · Score: 1

    separately-compiled in-process string objects _are_, in general, binary-compatible between versions (at least between "contiguous" versions). Or, better putting it, I, in my 15+ years experience with C++, have never found an instance where, for example, a DLL written with SomeCompiler version 8 would not work OK with an executable written with SomeCompiler version 9 WRT std::string or even floats and doubles.

    I agree with you that in-process marshalling is (in general, at least) silly.

    --
    It's better to be the foot on the boot than the face on the pavement. ~~ tkx Kadin2048
    1. Re:But... by ojQj · · Score: 1

      :o) Try compiling with different versions of MFC. CString isn't compatible between debug and release, much less from one version to the next. STLPort isn't compatible with MS STL either. I'll admit to only 6 years, but I've seen multiple instances of this problem. But we also aren't dealing necessarily with contiguous versions either.

    2. Re:But... by n00854180t · · Score: 1

      The problem cropped up at the seventh word of your sentence. Just don't use MFC :p

    3. Re:But... by ojQj · · Score: 1

      Yeah, I wish.

      We don't use it at interfaces anymore (I never did, but that's because I had the opportunity to learn from other people's mistakes...), but we also can't use the STL at interfaces for the same reasons -- different developer's prefer different versions of STL, and there are no guarantees that STL will remain compatible from one version to the next. You don't want to have to do without the latest version of the STL, just because of something silly like the binary compatibility of your string class. And you certainly won't be able to convince the developers that use your library to do without -- chances are about even they'll just do without your library instead. And multiple versions of STL don't get along in the same project. So there is no STL in our interface definitions either.

      This is the reality of programming for industry -- but I get the feeling you might know what I mean. :o)

    4. Re:But... by n00854180t · · Score: 1

      Indeed. There are so many unwanted compromises that we seldom get to work in our most efficient environment. Although, personally, I'd do almost anything to get away from MFC :P Write your own string class?
      I do know what you mean though. Currently I have to work to support Visual FoxPro 3.0 (yeah...insane) on a production database. The people in charge are too "afraid" to upgrade versions, even those that are mostly backwards compatible(or, for that matter, switch away from FoxPro to something better entirely). Their fear only gets worse as time passes and FP3 becomes more out of date.

  71. I doubt this guy's a security expert by ianalis · · Score: 2, Funny

    He's compiling as root :p

    1. Re:I doubt this guy's a security expert by Anonymous Coward · · Score: 0

      I tend to compile as root, install as root, and then never run as root. Go figure.
      Build scripts are easier to prove secure than multi-megabyte source trees.

  72. Why would I want to? by jc42 · · Score: 2, Interesting

    I think it's a bad mistake to make your code secure. If you look at sales figures, you see that sales are inversely proportional to security. So customers don't want secure computer software. If they wanted that, they'd buy it. Clearly, what people want is the most insecure software they can get.

    I say go with The Market, and write the most insecure software you can. Securing your software will only waste your time and decrease your sales.

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  73. You cannot know. You can only engineer. by natoochtoniket · · Score: 2, Insightful

    I think it was Knuth who said, "In theory, theory and practice are the same. In practice, they are not."

    In theory, for any nontrivial program, you cannot know absolutely that it is secure. You cannot even know that it will terminate. The Turing showed that there is no algorithm which will decide if a program will halt. Most other problems of program behavior can be reduced to halting. (Just place a call to exit() immediately after the code that outputs the behavior in question.) In general, there is no way to prove that a program has any particular property that can be reduced to a termination property.

    The choice of language does not matter, either. Turing used a language that was very primitive, even compared with the simplest assembly languages. But Turing's language is equivalent in computing power to every modern general-purpose programming language. Church's completeness hypothesis is widely accepted as valid, though a proof in the strict sense cannot be written. So, Turing's mathematical proof of the halting theorem is valid for every modern programming language.

    There are some programs for which we do know that the program is correct. Such programs are all very small, solve well-defined mathematical problems, and are written in well defined functional programming languages. These proofs depend on very careful, mathematical definitions of the programming language, and of the function to be computed. The programming language is, strictly, an algebra. The proofs simply show that the algebraic formula (the program) transforms the algebraic input to the correct algebraic output. In every case, such proofs are quite difficult and tedious. And, as noted above, they are not possible in the general case.

    In practice, we can apply methods that are known as "engineering". That is, we can apply logic, design, inspection, review, and testing to develop some amount of confidence that it will behave as expected. But, engineering methods do not provide certainty. They only provide high confidence. The choice of language and tools have some effect on the ease or difficulty of doing the engineering work, but do not change the boundaries of what is possible.

    How do we "know" that a bridge will not fall down. There are no proofs of bridges. There is only engineering. Engineers apply logic, experience, design, inspection, reviews, and tests, so that they can have confidence in the design. The confidence is based on statistics. For a given shape of steel or concrete, we can measure loads that cause the steel to fail, and we can measure the variance in those loads due to the manufacturing tolerances of the material. When we use that shape and material to build the bridge, we can have statistics about how much load the bridge can support without failing. But even with all that engineering, sometimes bridges do fall down. The load measurements are only statistics, not proofs. There is always a confidence interval around every measurement, and the confidence can never be 100 percent.

    We can never have absolute proof of any property of any real, nontrivial program. We can have confidence as close to 100 percent as we want, if we spend enough effort on the engineering.

  74. For every string function by ebuck · · Score: 2, Interesting

    For ever string function, there's an equivalent that will only perform the operation on the first n bytes. If you're working with a C library that's old and doesn't have such a convienece, you can always wrap it with a call that does.

    The real problems come into play when you're using a 3rd party library. You can always police your code, but it's hard to police / fix other's code. Open source libraries are great for this in general, but there's not always an open source solution for connecting to proprietary buses, services, etc.

    In the end, solutions that require policing are only as good as policing. Policing is designed to only be effective after some atrocity has been committed, and so policing will likely only be effective after the exploit. A much better solution would prevent use of unbounded string functions by not having them defined. Perhaps there's some compiler magic that could be employed, but I doubt such techniques will gain much traction. It's like asking a guild of master carpenters to switch building materials. Once you know the materials and weaknesses, usually it's better to design around the weaknesses than to change materials.

    As a pratical real-world example near me, our school system just replace over a million bricks in a nearby school. The reason was that the new-fangled iodized metal bolts were used (way back when) to bind the bricks to the sub wall. Iodized was new and "hot" and it didn't rust, so the wall should have lasted forever. However, it corrordes when exposed to salt water, and the school was close enough to the sea to be exposed to salt water vapor. The problem was discovered when a worker leaned against a brick wall and it toppeled over.

    In the end, education will bring the current coders around, but don't expect the problem to go away. There will be many years of people reading antiquated "how to program" books that teach older, less safe, practices. There will be people reentering the marketplace that will have missed the newer techniques. There will be users installing from the copy of winZip (or whatever) that they downloaded in 2000.

    Only with time, and a whole lot of paitence, will this problem die. It won't be fixed, it will decline until it's barely noticable.

    1. Re:For every string function by Ed+Avis · · Score: 1
      For ever string function, there's an equivalent that will only perform the operation on the first n bytes.
      However they're not always particularly intuitive and idiot-proof (which they need to be). It's regrettable that OpenBSD's strlcpy() is not included in glibc.
      --
      -- Ed Avis ed@membled.com
  75. Re:Don't use C++ as if it was only "C with classes by Anonymous Coward · · Score: 0

    Don't blame the tools. No matter the language, when you have input from unknown sources (i.e. a network) *never* trust the input.

  76. Re:Don't use C++ as if it was only "C with classes by Carewolf · · Score: 0, Flamebait

    There is no excuse for using STL. It is crappy, buggy, slow and impossible to debug.

    If you need higher abstraction features like that, you are using the wrong language. Try Java or C#

  77. Re:Don't use C++ as if it was only "C with classes by cnettel · · Score: 2, Insightful

    If you think that the flexibility and usefulness provided by C++ is present in Java or C#, then you are only using it as a nicer C.

  78. Re:Don't use C++ as if it was only "C with classes by Curien · · Score: 3, Informative

    And that's exactly why so many things are "implementation defined" or "undefined". Many real-world users of C++ demand that, for instance, vector::iterator be a typedef for a raw pointer for efficiency reasons. Other equally-important users would prefer an iterator type that guarantees sensible behavior in the face of real errors. The ISO standard allows for both behaviors by conforming C++ implementations.

    There's something attractive about the Java and C# languages having all constructs so well-defined. But both of those languages could afford not to support real hardware. Both target abstract machines and are happy with the results. C++ can afford no such conceit: it thrives in high-performance, customized, and otherwise exotic environments.

    --
    It's always a long day... 86400 doesn't fit into a short.
  79. Re:Don't use C++ as if it was only "C with classes by cnettel · · Score: 2, Informative

    Dynamic linking will also frequently create thunking tables close together, and lots of C code have other function pointer tables in special places anyway. (In a Win32 environment, you have that table for any COM object, it won't matter if you implement it in C, for example.)

  80. But generally, he's right. by shaneh0 · · Score: 1

    The majority of the time, when used as a verb, Affect is right, and when used as a noun, Effect is right. The fact that the guy is trying to effect change in this matter is a good thing.

    So remember, 95% of the time, A is for action, E is for everything else.

    1. Re:But generally, he's right. by maxwell+demon · · Score: 1

      Or simply remember that the Slashdot effect might affect you, not the other way round.
      Although I could imagine that being affected by the Slashdot effect might effect a Slashdot affect :-)

      --
      The Tao of math: The numbers you can count are not the real numbers.
    2. Re:But generally, he's right. by Simetrical · · Score: 1
      The majority of the time, when used as a verb, Affect is right, and when used as a noun, Effect is right. The fact that the guy is trying to effect change in this matter is a good thing.

      Well, yes. Except that the guy's sig has it the other way around.

      --
      MediaWiki developer, Total War Center sysadmin
    3. Re:But generally, he's right. by shaneh0 · · Score: 1

      holy crap.

      I didn't even notice that.

  81. Re:You cannot know. You can only engineer. by Anonymous Coward · · Score: 0

    Programming vs engineering using real life material
    - one major difference is that you cannot do destructive test to the actual building material for your project, so you have to settle for statistics to figure out how the untested material would work.

    Software on the other hand can be tested to failure. What's the excuse for not testing it?

  82. strncpy by Anonymous Coward · · Score: 0

    The problem of simple string boundary problems is solved in plain old C.

    Just that people don't use it because they think "ah, only my program will be running this code, so I already know it is fine.

  83. One more thing about OpenBSD by arthas · · Score: 3, Insightful

    Let's not forget their wonderful documentation! Complete and accurate API documentation is absolutely necessary for writing secure and reliable software. And of course the programmers should actually read the documentation and check all the details of the API calls they are using (return values, etc...)!

    1. Re:One more thing about OpenBSD by RAMMS+EIN · · Score: 1

      Unfortunately, even the OpenBSD documentation is not always clear and complete. I remember one instance where I wrote a HOWTO describing how to use OpenBSD's ccd for mirroring partitions, and one of the reactions I got was "don't use ccd mirroring; it's broken". Yet, ccd mirroring is is described in the ccd manpage, without any mention of it being broken, and without clear instructions for setting it up.

      --
      Please correct me if I got my facts wrong.
  84. Valgrind, efence, gcc (-Weffc, -fstack-protector) by savago_cpp · · Score: 1

    Valgrind can detect use of uninitialized memory, as also access to free'd memory, memory leaks and also unmatched free/malloc calls.

    You forgot to mention Bruce Peren's electric fence (http://perens.com/FreeSoftware/ElectricFence/), which will crash your program and generate a core dump in case you overflow/underflow (even by 1 byte) a given vector array. For C++ you can think about some variants, like DUMA.

    I think that for stack errors, gcc-4.x does provide some extra protection to detect stack smashing, too. (http://en.wikipedia.org/wiki/Stack-smashing_prote ction#GCC_Stack-Smashing_Protector_.28ProPolice.29 )

    For C++, g++ does provide a quite unique flag: -Weffc. This little baby checks for some of Scott Meyer's rules to write better code (believe, this one catches a lot of subtle bugs).

    Also, you can catch another bunch of code bugs with extensive/intensive unit tests. Recently I was involved in writing some nasty encode/decoding code between several charsets (think about GSM, UTF8, UTF16, UCS-2, etc). Even if we are going to support only english and german, we wrote some code to test other languages (chinese and arabic come to mind). It helped us to detect some missing logic on original code and detect some overflows.

    OSS/Free software developers does have a good bag of tricks to help develop and test software, I don't think that the situation is so bleak.

  85. Babies with C++? by Archangel+Michael · · Score: 1

    "Too many babies using C/C++."

    Wrong. Like Babies with knives and guns (from the GP), the problem isn't the babies, it is the parents fault for giving the babies the wrong freaking tools. Don't blame the babies, they don't know any better.

    So, the question is, what is the equivalent to plastic guns and knives in the programming world?

    --
    Agent K: A *person* is smart. People are dumb, stupid, panicky animals, and you know it.
    1. Re:Babies with C++? by finiteSet · · Score: 1
      So, the question is, what is the equivalent to plastic guns and knives in the programming world?
      Logo?
      --
      If we start buying CDs then the terrorists have already won.
  86. MOD PARENT UP by TheRaven64 · · Score: 1
    Whatever *NIX platform I am developing for, I keep a terminal window open for looking at the OpenBSD manual pages. They are always clear about things that are ambiguous elsewhere (e.g. whether caller or callee has to allocate / free memory, what happens in unusual situations).

    The worst offender I have found has been the OS X POSIX threading API documentation. This contains a number of very small errors, and if you write your code to the documentation, you will find things breaking in subtle and difficult to track down ways.

    --
    I am TheRaven on Soylent News
  87. Re:You cannot know. You can only engineer. by natoochtoniket · · Score: 1

    Software on the other hand can be tested to failure. What's the excuse for not testing it?

    I didn't say that you should not test. I said that testing is an engineering method. Testing cannot provide proof of correctness of nontrivial programs. But the reason may not be obvious to some.

    If a program accepts N bits of input, testing requires O(2^N) units of effort (time or parallel resource). For small values of N this might be possible. But nontrivial programs usually accept lots of input. Values of N greater than a few hundred quickly lead to intractable numbers of test cases. Most nontrivial programs will accept thousands or millions of bits of input.

    What's worse, many programs will accept arbitrarily large amounts of input. Try to imagine the number of possible key/mouse sequences that you could input into your browser, or into your word processor. The number of possible input sequences is countably infinite. The sun will burn out long before they can all be tested.

    At most, a vanishingly small fraction of the possible inputs can be tested. If those test inputs are randomly selected from the space of possible inputs, then they may be considered as a statistical sample of the program inputs, and the resulting outputs can be considered as a statistical sample of the outputs. But, at best, you still only have statistical confidence in the results.

    If you carefully choose the test cases, you may be able to use logic to gain increased "coverage", but then the population is not randomly selected, and so such methods fail to provide statistical confidence. An error or omission in the test-case selection may completely fail to select some cases that are actually very likely to occur.

    As an engineering method, testing can be quite useful. But testing can not provide proof of properties of nontrivial programs.

  88. Why bash C/C++? by DigitAl56K · · Score: 2, Insightful

    As a C/C++ developer I am a little offended by the article summary. Certainly C/C++ has a lot of flexibilities that allow bad developers to write bad code. However, many other languages, e.g. Java, allow bad programmers to write code that looks good because of stronger type checking, reduced use of pointers and the like. However, nothing stops a bad developer from writing insecure code in any language. Maybe you don't manage your resources correctly. Maybe you do a bad job of implementing encryption/protected storage. Maybe your authentication scheme is weak, your site is vulnerable to cross-site scripting vulnerabilities, or your session data can be easily spoofed.

    Secure code is not a product of language, it's a product of developers who take the time to fully understand the tools that they are using to build the product, including the ins and outs of their language of choice and its key risk elements, and who research risk elements for all other parts of the system.

    1. Re:Why bash C/C++? by Simetrical · · Score: 1
      As a C/C++ developer I am a little offended by the article summary. Certainly C/C++ has a lot of flexibilities that allow bad developers to write bad code. However, many other languages, e.g. Java, allow bad programmers to write code that looks good because of stronger type checking, reduced use of pointers and the like. However, nothing stops a bad developer from writing insecure code in any language. Maybe you don't manage your resources correctly. Maybe you do a bad job of implementing encryption/protected storage. Maybe your authentication scheme is weak, your site is vulnerable to cross-site scripting vulnerabilities, or your session data can be easily spoofed.

      Yes . . . but all those are true in C/C++, too, in addition to things like buffer overflows. There are fewer opportunities for serious error, and assuming you stay away from eval()-like functions, in interpreted languages there are no opportunities whatsoever for arbitrary code execution no matter how hard you try. If you're an expert and careful C/C++ programmer, sure, you'll write much more secure code than a novice and hasty Java programmer. But people of comparable expertise and carefulness will write more secure code in languages other than C/C++, and they'll probably write it faster too. The only major disadvantage is execution speed.

      --
      MediaWiki developer, Total War Center sysadmin
  89. Re:Don't use C++ as if it was only "C with classes by Profane+MuthaFucka · · Score: 1

    I have solved those problems completely with my infinitely large computer. It simulates all possible computer programs. Ultimately, writing any program that you desire boils down to a simple linear search. When asked when coding will be done, programmers can no longer use their stock answers "a half hour" or "two weeks". Even that is simplified to the single answer "on average, half of infinity ". Managers love that shit because it looks good on reports.

    --
    Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
  90. Re:Don't use C++ as if it was only "C with classes by Elazro · · Score: 1

    Your comments are valid, but if one is concerned about security, there are a number of steps to take. First, in regard to the STL (well, to be accurate, that part of the library which used to be called the STL), you can test and debug with a 'checked STL' implementation. Such an STL will detect all out of bounds accesses (not just when using 'at'). They can usually check a number of common iterator problems such as using invalidated iterators, an invalid iterator range (such as foreach(a.end(),a.begin()) ), mismatched iterators ( foreach(a.begin(),b.end()), and so on. STLPort provides one such implementation.

    As for problems with uninitialized variables and order-of-initializer problems, one should compile with full warnings on. These types of problems are easy for the compiler to catch, and once warned, usually easy for you to fix.

  91. Re:Don't use C++ as if it was only "C with classes by CastrTroy · · Score: 2, Insightful
    If bridge engineers were as lazy as programmers, bridges would be falling down by the hundreds.
    I don't understand why people continually compare programming with building bridges, or cars. Until every programmer has a software engineering degree, and managers actually give them the time and resources to program correctly, then this is not a fair comparison. The reason that software fails so often is that it's rushed out the door before it's ready, or because the programmers are guys who took a 3 month course at a career college and now think they are programmers, and that they know what they are doing. Until the same care is taken designing software as it is to design bridges, they can't be compared. Bad software is not the fault of "lazy programmers", but rather the fault of companies hiring incompetent programmers, or not giving the competent ones the time and resources they need to do the job.
    --

    Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
  92. My suggestion by TheLink · · Score: 0, Flamebait

    Don't write in C or C++ unless you absolutely have to. If you absolutely have to, make decent plans for dealing with the eventual security problems - like write the crap anonymously or using the name of some politician you decided you didn't like ;).

    There are plenty of other languages where a whole area of C/C++ problems just don't exist. Pick a decent language or two (Please NOT PHP! Forth is not much better than C). It'll still have problems, but at least you'd have a lot less "common programmer bug = attacker executes _arbitrary_ code of attackers choice" which should be totally unacceptable for modern code.

    I personally use perl, and so far none of the bugs found in the programs I write for work would allow an attacker to "execute arbitrary code". It's more likely that any such bugs would likely be a bug in perl or the 3rd party libraries I use (nyah spread the blame ;) ).

    If you don't like perl, you could use python or similar.

    Perl of course isn't fast (fast enough for a dhcpd[1]). But other languages like LISP, *ML are nowadays about as fast as C.

    If you don't like the other fast languages, write the bulk of the stuff in a slow safe language that you like. Then write the performance critical programs in C and try to keep those really small and secure.

    [1] Why a dhcpd in perl? We needed a fair number of features not in the isc-dhcpd and other dhcp servers. And go look at the source code of isc-dhcpd and a few other dhcp servers written in C sometime... Let me know what you think of the code ;).

    Why not Python? Existing Python libs don't allow us to make a dhcpd that does what we need.

    --
  93. Re:Don't use C++ as if it was only "C with classes by Jerry+Coffin · · Score: 1
    And automobiles can introduce problems (air pollution) that didn't previously exist with the form of transportation they replaced.

    I suggest you take a look at the smoke from a forest fire started by a spark from a steam locomotive. Then take a whiff of a town where every street is a foot deep in horse manure. Then come back and try to convince us that cars cause more pollution than their predecessors.

    Lack of pollution in the past is almost entirely a fantasy. Especially during the early industrial revolution, many cities (especially industrial centers) had air pollution so bad that they typically ran their street lights 24 hours a day.

    --
    The universe is a figment of its own imagination.
  94. partial solution by belmolis · · Score: 1

    They may not be complete solutions, but a few practices avoid a lot of problems:

    • NEVER use gets(3)
    • Use the versions of the string functions that count, e.g. snprintf(3) instead of sprintf(3)
    • Run your code through valgrind
  95. CRT checks in Visual Studio 8 by Anonymous Coward · · Score: 0

    Visual Studio 8 examines the use of the C run time library and will warn about security concerns. For example, the compiler will complain about 'strcpy' suggesting using the secure version. You must add a #define to disable this new feature if you want your existing code to compile.

    Also, the C/C++ journal is an excellent resource for writing good secure C/C++ code. There was an artical a few years back that demonstrated using stl:vector:pointer as parameters to CRT and Win32 API functions which add a layer of security.

  96. Re:Don't use C++ as if it was only "C with classes by Blakey+Rat · · Score: 1

    I didn't say they produced more pollution. Well, maybe I did, but I meant they introduced new problems that weren't problems before, but in every other way were better than the alternative. Excuse me for momentarily forgetting how pedantic Slashdot posters are that they would ignore the POINT of a post to nitpick some detail.

    Similarly, C++'s STL may introduce new problems, but it sure as hell fixes a metric ton of them in the process.

  97. Re:Don't use C++ as if it was only "C with classes by Jerry+Coffin · · Score: 1
    Why would you HAVE to use C or C+ or C*+**+++? I don't mean to be a troll, but if you are writing in an inherently insecure language (i.e., any compiled language) you aren't going to get secure code.

    OTOH of you write in, say, assembly, you are setting yourself up for the complexity. You have to make sure your buffers won't overflow, as opposed to leaving it to the compiler writers.

    I'm not sure what makes you think "any compiled language" is inherently insecure, but I'm pretty sure anything that would support such a claim would apply equally well to assembly language. An assembler is enough like a compiler that almost any characteristic inherent to one is virtually certain to be inherent to the other.

    My 1992 car is full of hundreds of thousands little bitty moving parts and fluids, but as long as I keep clean oil and filters in it, it doesn't break. My last car was an 1988, it lasted until last year. But I have to replace my 2002 Microsoft operating system because it's not secure?

    An utterly nonsensical comparison. The 2002 code does exactly what it did back then, just as well as it did back then. It won't ever wear out in the way your car did.

    If you insist on comparing a a computer to a vehicle, compare it to something like a tank or a jet fighter. It's a target in a hostile environment (i.e. a network), surrounded by enemies ready to exploit any weakness they can find.

    Somebody is making a lot of money off of poorly designed and poorly built software. There is no reason why I should have rto replace an OS.

    I suppose you also think the designers of WW I biplanes were lazy because they produced something that couldn't compete with an F15?

    There are reasons for program errors, but no excuses. If your code is shit, it's shit because you wrote shit. Either you're incompetent or lazy. "You can have cheap, secure, or fast. Pick two."

    Even the greatest chess masters lose occasionally -- and compared to programming, chess has simple rules, a well-defined goal, a stable environment, etc.

    --
    The universe is a figment of its own imagination.
  98. using malloc for memory allocations by robophobe · · Score: 1

    If you're writing C code and you're not wrapping your memory allocations/deallocations in a more fortified layer than malloc, you're asking for trouble. It's possible to do much more robust memory management and memory integrity checking if you do this. It's not foolproof, like many suggestions, but it can really help.

    --
    There was a time when movies had plots. So you knew who's ass it was, and why it was farting.
    -Not Sure
  99. Prove it. by mengel · · Score: 1
    Do at least the following

    Oh, and if you find anyone who's actually writing software that way, let me know, I may want a job there.

    --
    - "History shows again and again how nature points out the folly of men" -- Blue Oyster Cult, 'Godzilla'
  100. Halting problem, revisited. by mengel · · Score: 1
    Please stop repeating this misinformation about the halting problem. The only thing the halting problem proof proves is that you cannot write a program which correctly groups all programs into {the set of programs that halt on all inputs} versus {the set that loops forever on some inputs}. That doesn't prevent you, for example, writing one that says "always halts", "sometimes hangs", or "I can't tell", nor does it prevent you writing one that correctly identifies every program ever written to date into those buckets.

    Or to put it another way, it says there exist programs for which you cannot prove whether they halt. But it does not say that all programs have that property, only that there must exist at least one.

    --
    - "History shows again and again how nature points out the folly of men" -- Blue Oyster Cult, 'Godzilla'
    1. Re:Halting problem, revisited. by Procyon101 · · Score: 0

      Yes, but any language that does not suffer from the halting problem is by definition, not Turing complete. This makes such language's usefulness as a general computing language suspect, since introducing a construct as fundamental as recursion makes the language's halting unprovable.

    2. Re:Halting problem, revisited. by TheRaven64 · · Score: 1

      I was speaking in the context of an automatic theorem prover. Sure, you can write an automatic theorem prover than will say 'yes,' 'no,' or 'maybe' when you ask it if the program will halt, but in the vast majority of cases it will say 'maybe,' which is not actually a useful answer. The same is true of a lot of things that it might be useful to verify, which is why no one uses verification yet for anything other than trivial projects.

      --
      I am TheRaven on Soylent News
  101. Re:Don't use C++ as if it was only "C with classes by Anonymous Coward · · Score: 0

    I don't understand why people continually compare programming with building bridges, or cars. .... Until the same care is taken designing software as it is to design bridges, they can't be compared. .....

    So if we don't compare programming to engineering, how exactly will we GET that level of care?

    We SHOULD make the comparison, because software is just as vital to our economy as those other things, yet we don't demand it, we aren't willing to pay, vendors won't deliver, and government doesn't regulate it.

    The first step is realizing that, yes, it is possible to write software with a lower number of defects, and no, Johnny the philosophy major who picked up a book on Ajax is probably NOT going to be part of the team that delivers that secure web app.

  102. Making sure your code is secure for C by fyngyrz · · Score: 1

    Write an input routine that cannot be overflowed; takes it's characters one at a time, counts them, makes sure each byte is counted if they're multibyte, stops before filling the return buffer and positively terminates said buffer, obeys length restrictions from the caller which are REQUIRED in order for the routine to work in the first place, and preferably enforces some kind of sanity on the data itself (I want an int... a float... a double... ASCII... Unicode... a complex number... a url... etc.)

    Direct everything that takes data through this bottleneck. If you come up with a need for a new datatype, write it into the bottleneck. Don't write some new chunk that has to be maintained separately.

    Your program should never be exposed to a string it doesn't like, can't handle, or contains anything that doesn't look like exactly what you asked for.

    A similar approach is called for with regard to memory when using C. You should never let the OS manage memory using basic memory allocation controls. Provide, and mark boundaries on your memory. Track your use 100%. Check those boundaries for violations when the memory is being deallocated and at other times that seem prudent to you. At exit, call a general deallocator to clean up anything that is left over and scream bloody murder about if anything is found still allocated, and about any bounds that are written over. The time taken to write a fast memory allocator that watches for border excursions will be returned many times over in applications that don't leak, don't break and don't annoy your customers (or yourself.) You can, if you like, write this two ways: One for testing, where everything is turned on and will hair trigger, and one for release, where most of this stuff is off for speed... but frankly, you should keep everything on all the time, because your code should never screw up AND because a good reporting section will let you find a bug in about two seconds. And besides, it'll teach you to write fast memory allocation and testing code.

    Write a powerful linked list system. Aside from the fact that it's a great exercise, it has tons of uses for memory management and again, will pay for the time taken many times over. These are typically very small in terms of the code required for all manner of sophisticated and cool list handling functions, as is a memory manager. Input validation isn't that simple, or at least, not as you add significant numbers of well checked datatypes, but it is so useful that even if it does take a hundred k of code (it won't, I'm exaggerating) it's still worth it.

    One last thing: Don't use other people's code if they've buried input routines in it. Yes, that means that many objects are out of bounds. Tough. Man (or lady) up and write it yourself. If you don't know exactly what is in there, and you can't vouch that it is 100% safe, you have no business using it anyway.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:Making sure your code is secure for C by try_anything · · Score: 1

      The only answer for security in C is "write it yourself?" You've got to be kidding.

      Unless everyone writing C is still writing insecure code by default, which sounds unlikely since most people at least pretend to have wised up, there must be open source input validation libraries and/or some secure replacement for the standard C library.

      If you can't find high-quality open-source libraries that are secure by design (and I'd be surprised if you couldn't), then "Don't use C!" is much better advice than "Write it yourself."

    2. Re:Making sure your code is secure for C by fyngyrz · · Score: 1
      The only answer for security in C is "write it yourself?" You've got to be kidding.

      No, I'm not kidding in the least. If you can't do what I described, you're not a serious programmer anyway as far as I'm concerned. If you simply hadn't thought of it, I'd be forgiving, but remain insistent; if I had hired you to work for me and you said that you felt it was too much of an imposition to make sure your code was secure by your own efforts, you'd be back out on the street. If you could not write the above things in a reasonable amount of time... say a couple weeks total... you'd also be back on the street, and you'd never, ever get a chance to code for our flagship products. C is not a forgiving language. For the extra speed and efficiency, you have the freedom to completely screw up. You have to demonstrate to me that you won't. Our flagship app is a fraction of the size of its nearest competitor, does more, does it faster, and is considerably more reliable. That's because I don't accept excuses; I demand you meet the challenge or toddle off.

      In your own life, you're free to do whatever you want; my original post was passing along what I think is important, and of course you can take it or leave it. But please don't make the mistake of thinking I wasn't serious. I certainly was, and am.

      Unless everyone writing C is still writing insecure code by default, which sounds unlikely since most people at least pretend to have wised up,

      Simple question: If everyone has wised up, why are there new exploits appearing just about every day?

      If you can't find high-quality open-source libraries that are secure by design (and I'd be surprised if you couldn't), then "Don't use C!" is much better advice than "Write it yourself."

      There is no language out there that offers the efficiency and performance of C. If you want to provide the smallest possible application with the highest efficiency to your customers in some vague resemblance to a reasonable amount of time and at least one level of abstraction above assembler, there is no other choice. If your application doesn't require efficiency (and many do not) then something like Python is a lot more appealing. I'd use Python for everything if I could. It's a beauty of a language, and it solves tons of problems before you ever get to see them as a programmer. But it is pig slow compared to C, and so for things like graphics apps, it's not even remotely practical.

      Open source is also a minefield for many companies; again, you're better off to develop cleanly in house. The up front cost is a fraction of the cost of trying to navigate the myriad legal minefields represented by the mixture of OS/FOSS licenses out there. Of course, if you're not good enough to write your own reliable code in a reasonable amount of time, you'll have to compromise (or change jobs) because otherwise, you're not going to get anything useful done.

      Finally, using other people's libraries is one sure way to let other people introduce problems into your shipping product without you knowing about it. Write your own; now you have control, and no one else does. Your customers will benefit, as will you. Yes, it takes time. All good things do.

      --
      I've fallen off your lawn, and I can't get up.
    3. Re:Making sure your code is secure for C by tbo · · Score: 1

      If you can't do what I described, you're not a serious programmer anyway as far as I'm concerned.

      Look, there was a time when that was true, but that time has passed. What you're saying is in the same vein as "Real men use assembly" or "Compilers are for wimps". I could spend the time to write my own input validation library, just like I could learn assembly for every platform I might want to code for or teach myself compiler design, but I'd rather actually do something useful, like designing the hardware you'll be using in twenty years. Your point about libraries being a place for others to introduce vulnerabilities into your code is technically true, but irrelevant. Unless you hand-inspect your compiler at the binary level, you don't know your code is secure, and others can introduce backdoors into your code. Out of curiousity, do you allow your C++ programmers to use STL, or do they have to re-write that for themselves?

      More seriously, there should be libraries--ideally, BSD-licensed libraries--that do the kind of input validation you describe. Why do I say BSD licensed instead of GPL? Because everyone would benefit if software got more secure, even if it's software they don't use. I don't use Windows, but I'd be happy if it became more secure because it would mean I'd get less spam.

  103. Re:Don't use C++ as if it was only "C with classes by Jerry+Coffin · · Score: 1
    ...C++'s STL may introduce new problems, but it sure as hell fixes a metric ton of them in the process.

    Other than the minor detail of using the term "STL", I agree completely. Actually, I'm a bit surprised that nobody mentioned the problem that I think is most annoying: the fact that a truly trivial error can result in an error message that's three pages long and nearly impossible to decipher. Leor Zolman's stlfilt can help, but it's hardly a panacea. (And yes, if there are any other old farts like me reading, this is the same Leor Zolman who wrote BDS C, back before the continents separated and such...)

    In case anybody cares: I object to "STL" on the grounds that it's extremely ambiguous -- some people use it to refer to the entire STandard Library, others to refer to a library written years ago by Alex Stepanov, still others to a library currently maintained by SGI based on Alex Stepanov's library, and still others to those portions of the current C++ standard library closely based on Alex Stepanov's library (usually with a rather poorly defined boundary). Still others seem to use the term to refer to all code that uses templates. While ambiguity in English is hardly new or unique, this situation seems worse than usual to me -- enough to warrant avoiding the term altogether.

    --
    The universe is a figment of its own imagination.
  104. Re:Don't use C++ as if it was only "C with classes by jgrahn · · Score: 1
    Not necessarily , all I'm saying is that the STL can introduce bugs of its own that can be a lot harder to find than old style buffer overruns so its not a solution that will get rid of obscure coding (as opposed to logic) bugs.

    STL doesn't introduce bugs, you do. Never place objects which don't meet the minimum requirements for being placed in STL containers into STL containers, and you'll be fine. (If we're talking buffer overruns, aren't we talking about strings and std::vector, anyway?)

  105. Re:Don't use C++ as if it was only "C with classes by yermoungder · · Score: 2, Informative

    FUD alert!!!

    C# might be appropriate for your domain but it certainly isn't in Ada's - safety critical or mission critical systems.

    It's also easy to learn as can be seen here http://www.stsc.hill.af.mil/crosstalk/2000/08/mcco rmick.html

  106. Testing really helps with this. by Anonymous Coward · · Score: 0

    I wrote a buffer memory manager library with a well defined interface in C that had no buffer overflows in itself. It took me 3 days to implement the code. It took me another 3 days to write the test harness and fix all the bugs it found.

    The test harness was written to test every aspect of the design of the library. I ran the test with gcov a gnu code coverage tool to ensure that I exercised very code path. I then put multiple bizarre random values into every function call and made sure that I correctly handled every case, within reason. I tested it until it ran out of memory, to make sure that part worked and it would return appropriate error codes to the higher level system. I did assume that the function putting data into me did know how long their block of data was and that I could read through that block of data without an error. I also handled the case of a NULL pointer being handled correctly in any pointer that was passed to me. It took me another 3 days to write the test harness and fix all the bugs it found.

    That code, despite being fairly complex code that ended up getting used in many places in our product to replace buggy slow older code, never caused a single crash. All thanks to a few days of upfront unit testing.

    Well defined interfaces that obscure the access to lower level data structures combined with robust unit testing will save so much time and energy down the road.

    What I find annoying in C is that there is still no string data type that has a length associated with it as part of the language standard. C uses a string that is NULL terminated, which means that the terminator is part of the data stream. This is an awkward design that makes it impossible to elegantly design anything that can have to handle data with NULLs in it, which is nearly all data. That alone would go far in eliminating most of these overflows. Plus there would be a lot fewer bugs in a standard string type, a lot less than having everyone haphazardly having to design and implement their own string functions in every program written.

    If I could pass a string variable into read() then it could return to me the string with the length filled out. strlen() would be deprecated as no longer ever needing to be used.

    It is just crazy for everyone to have to invent or find their own version of string libraries to use, considering how much these libraries are used. The same goes for working with IP numbers.

    Let's bring the standard C library up to the 21st century!

  107. Re:Don't use C++ as if it was only "C with classes by Anonymous Coward · · Score: 0

    never store raw pointers in collections, always "objects".

    This will kill multithreaded programs. For example, resizing a vector can move it around in the memory, invalidating all pointers to all objects in the vector. Smart pointers might save your day (no experience), but they are not in the C++.

    This is one of the cases where C++ loses 10-1 to e.g. Java.

    If you really run into different behavior with different compilers, then at least one of the compilers is buggy.

    Or your code has a bug which becomes a defect only with some implementation(s), STL allows very different implementations e.g. for string.

  108. Re:Don't use C++ as if it was only "C with classes by swillden · · Score: 1

    This will kill multithreaded programs. For example, resizing a vector can move it around in the memory, invalidating all pointers to all objects in the vector.

    In a scenario like that, the objects in the vector should be smart pointers, not the ultimate referents themselves. So, the vector contents can be rearranged without affecting other smart pointers to the same referents.

    Smart pointers might save your day (no experience), but they are not in the C++.

    Yes, they are. If the ones in the standard don't provide the semantics you need, it's usually easy to find some that do. If you can't find any, then you can always create the ones you need.

    This is one of the cases where C++ loses 10-1 to e.g. Java.

    Your premises are faulty, hence your conclusion is faulty.

    Or your code has a bug which becomes a defect only with some implementation(s), STL allows very different implementations e.g. for string.

    Examples?

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  109. Re:Don't use C++ as if it was only "C with classes by angel'o'sphere · · Score: 1

    , especially since different compilers do different things under the hood. Thats an urban legend. Regarding to it can be a LOT harder to figure out whats really going on : certainly not. In C++ the bahaviour is well defined. And if you have troubel to debug a C++ programm and you assume copies (shallow or not deep enough etc.) or references are the problem, then set a break point in the constructor.

    If that does not help, then check for the methods that might get "synthesized" and if they are not defined, then define them!

    angel'o'sphere

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  110. GC is for whimps! by Anonymous Coward · · Score: 0

    In the old days, we didn't trust anyone else to handle our memory. We did it ourselves. Heck, I didn't trust smart pointers either.

    Either you know how to manage memory or you should be writing in a scripted language, not C/C++. Go back to PHP or Python if you must - or worse, Java where 95% of the programmers don't have clue about the OS they are running on. It really is quite sad.

    I'll continue to manage my memory myself, thank you very much.

  111. First you get your own silicon, then ... by Anonymous Coward · · Score: 0

    There is no security, if you are willing to assume sufficient lvl of attack.

    If you use a compiler, the compiler can insert code into your executable. One of the K&R guys did that to see how long it would go before being noticed.

    If you write your own compiler by handcoding in assembly, the chips themselves can do things they aren't supposed to.

    If you make your own chips, the silicon can be infected by nanomachines designed to etch extra pathways into your chips.

    Nevermind the fact that to design your own computer, you need advanced and therefore possibly compromised software. And you need an OS, which it's doubtful you can write your own (if you are skilled enough to both design your own computer and write your own OS, I salute you!), so thats another possible problem.

    And even if you make the perfectly secure system, starting from grains of sand you gather yourself, the second its out of your sight, it could be altered.

    Now, I admit, all of the above is fairly paranoid. There's very little reason for anyone to go to the extremes needed to embed compromising hacks at the chip or OS level. But there is no absolute security...

  112. Re:Don't use C++ as if it was only "C with classes by piranha(jpl) · · Score: 1

    an inherently insecure language (i.e., any compiled language)

    Hmm. Would you call Java, Haskell, OCaml, or Common Lisp "inherently insecure languages"?

  113. Re:Don't use C++ as if it was only "C with classes by Anonymous Coward · · Score: 0

    My 1992 car is full of hundreds of thousands little bitty moving partsand fluids, but as long as I keep clean oil and filters in it, it doesn't break. My last car was an 1988, it lasted until last year. I have a Mac Classic from 1990, it still works fine.
  114. bad advice! by r00t · · Score: 1

    Follow that advice if you want a horribly leaky app. As a bonus, adding threads will give you crashes left and right. Cleaning up the mess is extremely labor-intensive and difficult for even the most skilled developers.

    Boost is a pig. Pigs can fly, if you supply enough thrust. Rocket scientists are not cheap, and probably the pig will die anyway.

    Better advice:

    Stay far far away from boost. Always clearly document your object ownership and locking rules. Write your code to be simple, basic, non-nonsense, simple, clear, and simple. Debugging is harder than writing the code in the first place, so if you write the most clever code you can, you will not be able to fix all the bugs. Worship the KISS principle.

    1. Re:bad advice! by swillden · · Score: 1

      Follow that advice if you want a horribly leaky app.

      What are you talking about? Code written with use of appropriate smart pointers ensures no memory leaks at all.

      As a bonus, adding threads will give you crashes left and right.

      Equally ridiculous, unless you're dumb enough to share non-threadsafe smart pointers across threads.

      Boost is a pig.

      BOOST is a big collection of a variety of tools of different quality from different developers. Use what makes sense for the task at hand, and don't use the components that don't work well. There's a lot of excellent components in there.

      Always clearly document your object ownership and locking rules.

      Absolutely. Even better, document the ownership and lifetime by using a smart pointer with the right ownership semantics, tied to the right lifetime. In most cases that's not a reference counted pointer, in fact, it's usually an auto_ptr. As for concurrency, there are no silver bullets -- define and implement locking and access conventions, document the standards, comment the hell out of any cases that diverge from the conventions, and think hard about it.

      Write your code to be simple, basic, non-nonsense, simple, clear, and simple. Debugging is harder than writing the code in the first place, so if you write the most clever code you can, you will not be able to fix all the bugs. Worship the KISS principle.

      Agreed. And appropriate use of smart pointers makes your code much simpler, cleaner and safer than it would be otherwise.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    2. Re:bad advice! by r00t · · Score: 1

      So-called "smart pointers" (what an unbiased name, sheesh!) are very attractive to people from schools that teach all the CS classes in Java. These deceptively attractive constructs tempt people with the illusion that memory management can be ignored. This is indeed what people do. Reference counting is known to fail when loops are involved, and -- no surprise -- this is exactly what I see happen. Reference counting is no good when a "smart pointer" points to a struct full of regular pointers or similar. If you are good enough to not fuck things up in those ways, then you have no need for "smart pointer" crud in the first place! You might as well do things the traditional way and get the performance benefits of doing so.

      Heh. You said "dumb enough to share non-threadsafe smart pointers across threads". I've seen people do just that. I almost can't blame them, because these are supposed to be SMART pointers. They ought to know about being threadsafe!

      There is NO appropriate use of "smart pointers", which are neither pointers nor smart.

    3. Re:bad advice! by swillden · · Score: 1

      So-called "smart pointers" (what an unbiased name, sheesh!) are very attractive to people from schools that teach all the CS classes in Java.

      Just to be clear, I've been writing C++ professionally, not in academia, since 1993.

      These deceptively attractive constructs tempt people with the illusion that memory management can be ignored.

      People who believe that are simply wrong. That doesn't make smart pointers less useful to people who do understand memory management.

      Reference counting is no good when a "smart pointer" points to a struct full of regular pointers or similar.

      Why do you assume that I'm referring to reference counting? Reference counting should only be used when the design would be constrained unacceptably by associating object lifetime with some other object or stack frame. As I said before, auto_ptr is the most generally useful smart pointer. If you think that auto_ptr does reference counting, then your C++ standard library knowledge is sorely lacking.

      If you are good enough to not fuck things up in those ways, then you have no need for "smart pointer" crud in the first place!

      The advantage to using the smart pointer is that it takes care of the bookkeeping for you. For example, if you write a class whose ctor creates a handful of objects and you use auto_ptrs to refer to them rather than raw pointers, you don't have to manually ensure that you delete them all in the dtor.

      A key idiom in C++ programming is "resource acquisition is initialization". Smart pointers are essential to applying this idiom to the most important resource that your program manages -- memory.

      Further, if you make use of C++ exceptions, smart pointers are almost mandatory. There are scenarios in which the *only* way to make sure that proper cleanup occurs is to perform that cleanup in a destructor.

      You might as well do things the traditional way and get the performance benefits of doing so.

      There is zero performance benefit to doing things the C way. Simple smart pointer operations all get inlined and do exactly what you'd have to do yourself -- except that the compiler makes sure it happens.

      Heh. You said "dumb enough to share non-threadsafe smart pointers across threads". I've seen people do just that. I almost can't blame them, because these are supposed to be SMART pointers.

      The people of which you speak do not know how to use C++ correctly. Neither do you, actually, although they're worse off than you are. One of the key benefits of C++ over C (and many other languages) is that way that you can use templates to implement design patterns and coding conventions directly in code, so that the compiler takes care of all of the tedious details, at no run-time cost. None of this means you can be ignorant of what those templates are doing, or what code is ultimately being produced.

      They ought to know about being threadsafe!

      Then use threadsafe smart pointers! In particular, use a smart pointer that implements exactly the locking strategy that you would implement if you were using raw pointers. And then you can rely on the compiler to ensure that the locking work is never forgotten. Have cases where you *know* for some reason that the locking isn't necessary? Great! Add another assignment-compatible smart pointer class that skips the locking, and assign to an instance of that type and do your work. The assignment will clearly document what you're doing, without the need to add comments that may someday become misleading, and you'll have zero overhead. Even better, implement the non-locking version so that it actually checks the lock state when in debugging mode.

      There is NO appropriate use of "smart pointers", which are neither pointers nor smart.

      Not if you're a C programmer using C++ as "C with classes".

      If, however, you're a C++ programmer, there are almost no uses for raw pointers except when implementing your smart pointer classes, or when dealing with libraries that need them.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  115. Re:You cannot know. You can only engineer. by starfishsystems · · Score: 1
    How do we "know" that a bridge will not fall down. There are no proofs of bridges. There is only engineering. Engineers apply logic, experience, design, inspection, reviews, and tests, so that they can have confidence in the design. The confidence is based on statistics. For a given shape of steel or concrete, we can measure loads that cause the steel to fail, and we can measure the variance in those loads due to the manufacturing tolerances of the material. When we use that shape and material to build the bridge, we can have statistics about how much load the bridge can support without failing.

    Implicit in all of this is the use of a relatively small range of materials with well defined properties. Software is made out of ... bits. No material properties, thus very hard to predict its behavior.

    --
    Parity: What to do when the weekend comes.
  116. Java isn't ported everywhere by tepples · · Score: 1

    If you need higher abstraction features like that, you are using the wrong language. Try Java or C#

    What happens when I need higher abstraction features like those of the C++ standard library, and I am developing for an existing hardware platform and operating system that has a C++ compiler but not a Java or MSIL virtual machine?

  117. Re:Don't use C++ as if it was only "C with classes by tepples · · Score: 1

    Developers can chose their employer.

    Developers cannot choose where their parents raise them. Or is it usual for a person who has never been employed before to relocate internationally to find work?

  118. Re:Don't use C++ as if it was only "C with classes by shutdown+-p+now · · Score: 1
    The difference between pure C/C++ and the STL is that something like strcmp can create a rather subtle sort of buffer overflow error
    Correct me if I'm wrong, but isn't it called buffer overflow only when you write outside the buffer? I don't see how strcmp can cause this sort of behaviour; in fact, assuming that strings are properly null-terminated, it won't go out of bounds at all. You might have meant strcpy?

    Either way, the thing is, STL has direct equivalents to both, with the same quirks - namely, lexicographical_compare (okay, so it requires end of sequence to be defined explicitly, and is thus more akin to strncmp) and copy. Both can go out of bounds, the latter particularly easily since it does not even know the end of one of the sequences. Then there's insert_iterator and friends - all the same problems there.

    So, no, relying on STL algorithms won't make things much better. C++ is still C++, and you still have to be very careful to avoid accidentially pointing the gun at your foot.

    Of course, as another reply to my post mentioned, one can (and should) use a checked-iterator STL implementation for debugging. But such things exist for C as well.

  119. Re:Don't use C++ as if it was only "C with classes by shutdown+-p+now · · Score: 1
    Then there's insert_iterator and friends - all the same problems there.
    My mistake here, sorry - serves me right for reading Slashdot at 8am ;)
  120. If I don't do this, I'll starve by tepples · · Score: 1

    Patient: It hurts when I do this.... ouch!

    Physician: Don't do that then.

    Patient: If I don't do this, then my boss will stop giving me paychecks, and I can't buy food anymore.

    Now what does the physician say?

  121. Battery powered by tepples · · Score: 1

    The real problem was the widespread decision to use such a high level assembly language as if it were suitable for general purpose development.

    The real problem was the widespread decision to use low-spec battery-powered devices, which can last long on a charge precisely because they are underpowered, as if they were suitable for general purpose computing.

  122. Does Java draw too many milliamps? by tepples · · Score: 1

    I'm not sure that the efficiency increase from dropping boundary checks is often necessary, except possibly in high-end 3D games.

    Or on computing devices that are extremely limited in the amount of current they can draw. Think of microcontrollers.

  123. Because libc is ubiquitous by tepples · · Score: 1

    Where is it written that all software must be written in C or C++? Is anyone capable of independent thought? There are plenty of fine languages that are safe. Ada comes to mind. Maybe others will come to your mind (if you have one).

    Is the Ada standard library ported to my target platform (which is not Windows nor Mac nor POSIX)?

  124. Sometimes the platform dictates the language by tepples · · Score: 1

    After all, why write

    baz = malloc(strlen(foo) + strlen(bar));
    sprintf(baz, "%s%s", foo, bar);

    if you could write

    (string-append foo bar)

    etc.

    Because your development kit provided by the platform vendor comes with a C environment and not a Lisp environment.

  125. Still intractable by tepples · · Score: 1

    So there IS in fact a program that can determine whether a certain program that I'm about to run on my machine will halt on a given input. The program is simple: you count the total number of states the machine could enter, and then you run the program on a machine simulator for exactly that many "cycles." If it hasn't halted by then, it won't.

    How many states are in your ThinkPad, and for how many machine cycles has the universe existed?

    1. Re:Still intractable by dkoulomzin · · Score: 1

      Intractible is WAY better than unsolvable. I wasn't saying it was easy. Just that it's possible.

      --
      Thou shalt not begin a subject line or post with the word "Umm".
  126. Buffer overflows, memory allocation, etc. by Berkana · · Score: 1

    In FP, as far as I remember, nobody does their own memory allocation, so memory allocation exploits would not be attacking your program, but the implementation of the FP system you're using. If your computational model is purely functional, memory allocation exploits would be pretty much impossible, as far as I understand.

    I don't know if this is true in general, but as for buffer overflows, at least in Scheme and Lisp, if you handle input using lists, or even circular or recursive lists (as opposed to arrays that can be overflowed), it is impossible to overflow a buffer to attack other parts of the computer memory. Then, whatever you're going to input that list to (or circular/recursive list) should simply filter and check the input to make sure it is the right domain for the function handling it.

  127. Okay, I admit that mistake. But how about this? by Berkana · · Score: 1

    How about instead of testing IsSecure(), testing HasNoKnownModesOfInsecurity() to sweep for a list of the most common attacks? You can automate that in FP a lot more easily than you can with imperative languages.

    I know that at least in Scheme and Lisp, since the syntax is so simple (all the code is just a bunch of nested lists, and nested lists are effectivley trees), code auditing is simply a depth-first-search examination; check each part for known and common attacks.

    That's what I mean by automated code auditing. If you can't know that the code itself is totally secure, you can at least know that it contains none of the common known vectors for attacks. This is a lot lower threshold to satisfy than checking for total security, and I suspect in most cases, it is sufficient to defend from all but the most sophisticated attacks.

  128. Re:Don't use C++ as if it was only "C with classes by try_anything · · Score: 1
    We SHOULD make the comparison, because software is just as vital to our economy as those other things, yet we don't demand it, we aren't willing to pay, vendors won't deliver, and government doesn't regulate it.

    You seem to be saying that people who purchase software tend to harm the economy by purchasing cheaper, lower-quality software than they should. How in the world did you make that determination? Perhaps most software is made to an appropriate level of quality, with some being better and more expensive than it should be, as well as some being worse and cheaper.

    To go another step, if I were to claim that hundreds of millions of dollars were wasted every year making software needlessly good, and this unnecessary dedication to quality was harming the economy, how would you refute that?

  129. Laws of construction by cheros · · Score: 2, Insightful

    Seems the process follows the laws of construction instead, as aggregated below:

    1 - measure with a micrometer
    2 - mark with chalk
    3 - cut with an axe
    4 - if it doesn't fit, use a larger hammer :-).

    --
    Insert .sig here. Send no money now. Owner may sue, contents will settle. Batteries not included.
  130. Re:Don't use C++ as if it was only "C with classes by Anonymous Coward · · Score: 0

    You are getting confused between programming languages and foreign languages. Or are there countries so small that only one programming language is in use there?

  131. Re:Don't use C++ as if it was only "C with classes by Eivind+Eklund · · Score: 1
    To my mind, the problem is in several of parts.

    The first one is that we don't get the max amount of quality out of our dollars. There's a large amount of quality available "for free", as the research (and my experience) shows that it takes as long time to create high quality as low quality software, because there's so much time wasted on debugging etc in the low quality case that the lowered development time does not pay off. Extremely high quality is a different beast, with greatly increased costs.

    The second part is that the consumers do not know what quality they buy. Quality is a "negative feature" - consumers tend to assume it is there, and get annoyed when it isn't, and it's hard to acertain before doing a purchase and using the product. To make the market work ideally here, the purchasers should have perfect information. That's of course impossible, yet it's possible we could make things better with some sort of labelling system - if we could make a reasonable one (and that's a non-trivial problem in itself).

    Another problem is that having high quality may not be a sales booster *even if the price is the same*. Having low quality means that users invest more emotions in their software as they learn to work around bugs etc, and that they are more afraid of testing other things, as they've had to invest so much in this software (and think they'll have to invest as much in a new type.) This skews the market away from rational self-interest (which would discount investment to present value, as in "don't throw good money after bad") and towards the lower quality variants.

    I'm not sure how far from optimal this move the market; quite a bit, I think, but probably not as far as many people think.

    Eivind.

    --
    Doubting the existence of evolution is like doubting the existence of China: It just shows that you're uninformed.
  132. Re:Don't use C++ as if it was only "C with classes by Metasquares · · Score: 1

    You're correct; I meant strcpy.

  133. Re:You cannot know. You can only engineer. by HaveNoMouth · · Score: 1

    Bravo. Well-said.

  134. Simple: use COBOL! by avanaardt · · Score: 1

    [Ducks and runs]

  135. talloc() by Trogre · · Score: 1

    On this topic, how many people here are using talloc() ?

    --
    "Nine times out of ten, starting a fire is not the best way to solve the problem." - my wife
  136. Re:Don't use C++ as if it was only "C with classes by tepples · · Score: 1

    Maybe not countries, but there are geographic areas so small that only one kind of application is developed there. For instance, if I have a degree, and I want to gain experience in order to become eventually independent from my parents, and my parents live where the only available programming jobs are for web developers, and I want to develop video games, what should I do? Even in North America, where countries are generally larger than in most of the rest of the developed world, is it usual for somebody who has never been employed to relocate from Indiana to the State of Washington for his or her first job?