Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There's some confusion about line 335 of clnt_dg.c #135

Open
zhengyf opened this issue May 24, 2018 · 2 comments
Open

There's some confusion about line 335 of clnt_dg.c #135

zhengyf opened this issue May 24, 2018 · 2 comments

Comments

@zhengyf
Copy link

zhengyf commented May 24, 2018

if (addr->len < sizeof(cu->cu_raddr)) {

Let's see the code as follows

addr = (struct netbuf *)info;
if (addr->len < sizeof(cu->cu_raddr)) {
	rslt = false;
	break;

}
(void)memcpy(&cu->cu_raddr, addr->buf, addr->len);
cu->cu_rlen = addr->len;
break;

I think the condition of 'addr->len < sizeof(cu->cu_raddr)' is normal while the addr is for IPV4.

We should avoid the condition of 'addr->len > sizeof(cu->cu_raddr)' to prevent memory access out of bounds at '(void)memcpy(&cu->cu_raddr, addr->buf, addr->len);'

Is 'if (addr->len < sizeof(cu->cu_raddr)) ' supposed to be 'if (addr->len > sizeof(cu->cu_raddr)) ' ?

@dang
Copy link
Collaborator

dang commented May 24, 2018

No, the API here takes a struct sockaddr_storage, so that it can easily handle all address types. You're right that we should be checking the max length, so if anything the check should be
(addr->len != sizeof(cu->raddr))

@zhengyf zhengyf changed the title There's some cinfusion about line 335 of clnt_dg.c There's some confusion about line 335 of clnt_dg.c May 25, 2018
@ffilz
Copy link
Member

ffilz commented Dec 5, 2024

Should we fix this or can we close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants