Click here to Skip to main content
15,915,093 members

Survey Results

Who should take responsibility for library function calls?   [Edit]

Survey period: 17 Feb 2003 to 23 Feb 2003

When a library function is called, who is responsible for ensuring that the input data will not cause a program to crash, or worse - be susceptible to a security hole?

OptionVotes% 
The programmer calling the function should ensure the supplied input data is valid.11210.82
The programmer who wrote the library function should ensure that all input data is valid.43341.84
Both library function writer and caller should validate all input data independently.44042.51
Neither - just use try...catch blocks to handle any problems.504.83



 
GeneralData validation Pin
Anders Dalvander16-Feb-03 20:14
Anders Dalvander16-Feb-03 20:14 
GeneralRe: Data validation Pin
Tim Smith17-Feb-03 8:08
Tim Smith17-Feb-03 8:08 
GeneralOpen Source Pin
Anders Dalvander17-Feb-03 8:51
Anders Dalvander17-Feb-03 8:51 
GeneralRe: Open Source Pin
Anders Dalvander17-Feb-03 9:07
Anders Dalvander17-Feb-03 9:07 
GeneralRe: Open Source Pin
#realJSOP18-Feb-03 2:21
professional#realJSOP18-Feb-03 2:21 
GeneralRe: Open Source Pin
Anders Dalvander18-Feb-03 2:39
Anders Dalvander18-Feb-03 2:39 
GeneralRe: Open Source Pin
#realJSOP18-Feb-03 3:42
professional#realJSOP18-Feb-03 3:42 
GeneralRe: Open Source Pin
Anders Dalvander18-Feb-03 5:16
Anders Dalvander18-Feb-03 5:16 
John Simmons / outlaw programmer wrote:
You're taking all this completely out of context.
- You're the one that started to talk about horse manure. Wink | ;)

I'm talking about how the library function handles the parameter itself, not about the parameters you're going to pass to it.
- How should this be done, then? I'm not sure that I'm following you...

If your library is well written, a programmer could pass in any pointer and the application using your library should be able to recover gracefully from a brain fart-induced pointer reference.
- How should it do that? If the signature of the function is void foo(bar* pbar) and the caller passes a pointer to an int to the function how would I know that (without using the memory access functions that I've been hung up on), and what should I do about it?

Fortunately, the compiler tries valiantly to keep you from passing in pointers of the wrong type
- The compiler is good at that, but there are always wicked programmers that are doing casts.

but no matter what the programmer passes in, if your function is eventually entered, it should handle whatever parameter is passed to it.
- If the programmer are doing casts to make it compile, how would the callee know that?

However, an ASSERT in a library function is a BAD DESIGN IDEA for the reasons I already stated (don't have the source code).
- If I do an assert(pbar != NULL) the message that the programmer will get is 'pbar != NULL'. It is somewhat helpful, don't you think? Or if I do an assert(!"foo() - pbar cannot point to a bar object"), would that hurt?

If it's a bad idea in one instance, it's ALWAYS a bad idea.
- Ok, ok, you don't have to use assert if you don't want to.

Your debug version should work the same way as your release version.
- The debug version is for debugging the release version, it should contain more debugging information.

If your documentation states that a programmer can pass in any pointer type, then your function should be ready to handle that, but NOT through the ASSERT mechanism.
- True, if the documentation states that it can take any type of pointer, yes. But if it states that it should take a pointer to a specific datatype and the programmer passes another type to the function (using casts) it cannot possibly know that.

I stand by my claim that your views on library code are a crock of horseshit.
- There you go again, talking about horse manure. Wink | ;)

No matter what you are writing, the code should be flawless first, and fast second.
- I agree, code should be flawless. The function I have written is flawless, it is the callee that are flaw.

Writing a library for a programmer is exactly the same as writing a program for an end user.
- Yes, the programmer may actually be the end user.

It's YOUR job to make sure the programmer can't get away with doing something stupid.
- Noone can stop programmers from doing stupid things.

Like I said before, the compiler keeps you from having to do a lot of the type checking.
- Yes, but the wicked programmer from the above example does casts, so you cannot trust the compiler.

Why are you hung up on the memory access functions?
- How should I otherwise know if I could use the pointer that the wicked programmer have sent to my function.

How many processes of yours allow themselves to be hi-jacked in such a manner as to have read/write access to memory changed by an external process?
- Zero. But the wicked programmer will surely make the numbers increase. Wink | ;)

Enough of this nonsence, all I wanted to point out is that the caller could always send data to functions that are invalid in some way. It is practically impossible to prevent this from happening.
GeneralRe: Open Source Pin
Anonymous18-Feb-03 5:18
Anonymous18-Feb-03 5:18 
GeneralRe: Open Source Pin
Anders Dalvander18-Feb-03 7:19
Anders Dalvander18-Feb-03 7:19 
GeneralRe: Open Source Pin
Anders Dalvander18-Feb-03 5:34
Anders Dalvander18-Feb-03 5:34 
GeneralIt depends... Pin
Paul M Watt16-Feb-03 18:29
mentorPaul M Watt16-Feb-03 18:29 
GeneralRe: It depends... Pin
Jeff J16-Feb-03 21:39
Jeff J16-Feb-03 21:39 
GeneralRe: It depends... Pin
Navin17-Feb-03 7:56
Navin17-Feb-03 7:56 
GeneralAnd then...? Pin
Shog916-Feb-03 18:10
sitebuilderShog916-Feb-03 18:10 
GeneralRe: And then...? Pin
NormDroid17-Feb-03 3:07
professionalNormDroid17-Feb-03 3:07 
GeneralRe: And then...? Pin
Tim Smith17-Feb-03 8:06
Tim Smith17-Feb-03 8:06 
GeneralRe: And then...? Pin
#realJSOP18-Feb-03 2:18
professional#realJSOP18-Feb-03 2:18 
GeneralRe: And then...? Pin
bgiraya18-Feb-03 4:28
bgiraya18-Feb-03 4:28 
GeneralRe: And then...? Pin
Lunchy17-Feb-03 4:09
Lunchy17-Feb-03 4:09 
GeneralRe: And then...? Pin
Jon Taylor17-Feb-03 22:34
Jon Taylor17-Feb-03 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.