Skip to content

Fix uninitialized variable accesses in sockets/conversions #10966

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ext/sockets/conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ static void from_zval_write_sockaddr_aux(const zval *container,
zend_llist_add_element(&ctx->keys, &node);
from_zval_write_int(elem, (char*)&family, ctx);
zend_llist_remove_tail(&ctx->keys);

if (UNEXPECTED(ctx->err.has_error)) {
return;
}
} else {
family = ctx->sock->type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would moving this to be an unconditional set prior to the if branch get rid of the compiler warning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. However, then we unconditionally do a memory load in all cases. So I'd prefer to just write a dummy value in the non-else branch and commit that on its own to master (similar for the other warning). WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me :)

}
Expand Down Expand Up @@ -1115,7 +1119,10 @@ static void from_zval_write_controllen(const zval *elem, char *msghdr_c, ser_con
* this least common denominator
*/
from_zval_write_uint32(elem, (char*)&len, ctx);
if (!ctx->err.has_error && len == 0) {
if (ctx->err.has_error) {
return;
}
if (len == 0) {
do_from_zval_err(ctx, "controllen cannot be 0");
return;
}
Expand Down