Suspected bug in getpeername and getsockname
Actually, you are correct about that.
The reasons why I wanted to pass the address is length is
1. It gives more flexibility for any body implementing the protocol specific code.
2. We anyway copy the length in move_addr_to_user, we might as well do it in the system call and pass the length to the protocol.
3. We can finally copy only the length specified back to the user as we do currently.
I correct my self, it is not a BUG.
But, consider a case where a user passes a negative value in len. The system call calls the protocol specific code and then later at the end in move_addr_to_user() catches the error. I feel the error should be caught first hand, we should not have spent the time and space calling the protocol specific code at all, we should catch the error and return immediately.
I feel there are several instances of this in the socket system calls.
Don't u feel they should be fixed.
Balbir
Quoted 8 lines
If
move_addr_to_user()takes care of all of the issues, there is no reason for the protocol specific code to know anything about the user's len at all.You have to show me a purpose for it to get passed down. What would it get used for? All the protocol specific could should (and does) do is provide the data back to the top level routine and
move_addr_to_user()takes care of the remaining details.
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
From: "Balbir Singh" <[email protected]>
Date: Thu, 17 Jan 2002 14:11:06 -0800
The reasons why I wanted to pass the address is length is
1. It gives more flexibility for any body implementing the protocol specific code.
And you could do what with this flexibility that can't be taken care of at the top level?
2. We anyway copy the length in move_addr_to_user, we might as well do it in the system call and pass the length to the protocol.
Why? What are you going to DO, read this: _DO_, with the value?
3. We can finally copy only the length specified back to the user as we do currently.
We already do this in move_addr_to_user. If we do it in one place, we don't have to duplicate (and thus risk bugs in) this logic in the various protocols.
But, consider a case where a user passes a negative value in len.
Now you are totally talking non-sense. A negative len is an error (-EINVAL) and move_addr_to_user handles this case just fine.
I feel the error should be caught first hand, we should not have spent the time and space calling the protocol specific code at all, we should catch the error and return immediately.
...
Don't u feel they should be fixed.
If you want to move the "if (len < 0) return -EINVAL;" right before the ->getname() invocation, feel free. However, this is code duplication and is error prone.
But either way, this is not an argument at all to move the user len into the protocols. YOU DONT NEED TO, and you never will, to accomplish any legitimate task.
Again the question remains, why would you ever need the user len in the protocol handlers? All I am hearing is a bunch of hot air so far with no real substance.
Franks a lot,
David S. Miller
[email protected]