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

SET_SS_LEN constant conversion when sizeof(struct sockaddr_storage) == 256 #255

Open
phy1729 opened this issue Aug 1, 2021 · 1 comment

Comments

@phy1729
Copy link
Contributor

phy1729 commented Aug 1, 2021

sizeof(struct sockaddr_storage) on OpenBSD is 256; however, struct sockaddr's sa_len is a uint8_t. This means that SET_SS_LEN(..., sizeof(struct sockaddr_storage)) will set sa_len to 0 e.g.

SET_SS_LEN(&vaddr[0], sizeof(struct sockaddr_storage));

I think the least bad option would be to take the min of the second argument and 255

diff --git a/librb/include/rb_lib.h b/librb/include/rb_lib.h
index c02dff68..d702343c 100644
--- a/librb/include/rb_lib.h
+++ b/librb/include/rb_lib.h
@@ -171,7 +171,7 @@ char *rb_strerror(int error);
 #define SET_SS_LEN(x, y)	do {							\
 					struct sockaddr *_storage;		\
 					_storage = ((struct sockaddr *)(x));\
-					_storage->sa_len = (y);				\
+					_storage->sa_len = (y) < 255 ? (y) : 255;	\
 				} while (0)
 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len)
 #else /* !RB_SOCKADDR_HAS_SA_LEN */
@aaronmdjones
Copy link
Member

Should this not be reported to the OpenBSD developers instead?

It seems rather silly that they'd make one of their sockaddr structures too large to assign to the length field.

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

No branches or pull requests

2 participants