troglobit / smcroute

Static multicast routing for UNIX
https://troglobit.com/projects/smcroute/
GNU General Public License v2.0
244 stars 63 forks source link

Casting to wrong type #183

Closed alexeys85 closed 2 years ago

alexeys85 commented 2 years ago

The return type of recv call is ssize_t, at least on linux, somewhere else it could be just int. And -1 return value indicates about error. But at least here: https://github.com/troglobit/smcroute/blob/08289187975894a5748a3a478a0fb9f900274722/src/ipc.c#L176 it casts to size_t which converts -1 to non error value.

troglobit commented 2 years ago

Nice catch! You say "at least here", I cannot seem to find any other cases of recv() and size_t, are you perhaps referring to uses of read() which stores result in int?

alexeys85 commented 2 years ago

Well, I haven't found this issue anywhere else as well, just wanted to say that where are could be more places for you to check :) While at it, is it really necessary to force errno to be ECONNRESET in case of 0 or negative return value?

troglobit commented 2 years ago

OK, I see. Well then I didn't miss anything.

Re: ECONNRESET; yeah it was chosen to signal EOF (when recv() return 0) back to ipc_read(). On -1 it should return the errno of the syscall -- as you pointed out in this report.