Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Likely defect fix for issue #42. #46

Merged
merged 3 commits into from
Nov 1, 2017

Conversation

sftwrngnr
Copy link
Contributor

Check connection->type to ensure that it is not evhtp_type_client. Also checked for c->htp to not be null in a couple of ssl related functions.

sftwrngnr and others added 2 commits October 26, 2017 09:10
is not evhtp_type_client. Also checked for c->htp to not be null in a
couple of ssl related functions.
- Fix issue with non-SNI vhost sets
  * A few releases back, we replaced typed settings to a flag bitmask
    There was some logic previously that did the following:
      if (c->htp->parent && c->vhost_via_sni == 0)

    Where c->vhost_via_sni is NOW `EVHTP_CONN_FLAG_VHOST_VIA_SNI` in
    the flags mask.

    Unfortunately, the logic above broke when it was converted to a
    flag, and it causes the conditional to ONLY branch true if the virtual
    host was set by SSL SNI instead of the reverse.

    Simply put, the fix is: `!(conn->flags & EVHTP_CONN_FLAG_VHOST_VIA_SNI)`
    (note the '!').

- Lot's of cleanup on readability and logic for htp__connection_writecb_
- Added some more detailed commentary for obscure conditionals.
- Use `evhtp_safe_free` for any free's in htp__connection_writecb_

NOTE: M<3D
@NathanFrench
Copy link
Collaborator

Added 440e5b9 to your patch.

Can you verify things still function the same? Seems to work fine for me.

@NathanFrench
Copy link
Collaborator

NathanFrench commented Oct 26, 2017

Let's get a good set of eyes to make sure everything here is covered properly (note we no longer assert on potential errors). I also found a logical flaw for virtual hosts due to swapping out variable fields into bitmasks in the last release.

We need to verify the logic of https://github.com/criticalstack/libevhtp/blob/1.2.11n/evhtp.c#L1843 matches up with correctly with our bitmask changes.

This little refactor is a result of giving issue #42 a closer analysis.

@NathanFrench NathanFrench changed the title Likely defect fix for issue 42. Likely defect fix for issue #42. Oct 26, 2017

if (c->htp->parent && c->flags & EVHTP_CONN_FLAG_VHOST_VIA_SNI)
if (conn->type == evhtp_type_server)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be appropriate to use evhtp_likely here, or is that pointless?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I actually hate the idea that this is a connection tagged function - but references other types outside of the evhtp_connection_t struct.

I don't think it's needed here since there is not a false condition.

@@ -2680,6 +2744,10 @@ htp__ssl_add_scache_ent_(evhtp_ssl_t * ssl, evhtp_ssl_sess_t * sess)
int slen;

connection = (evhtp_connection_t *)SSL_get_app_data(ssl);
if (connection->htp == NULL)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should evhtp_unlikely be used here given that this condition is unlikely to occur?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not even sure if that code is even used, to be honest :)

@@ -2703,6 +2771,10 @@ htp__ssl_get_scache_ent_(evhtp_ssl_t * ssl, unsigned char * sid, int sid_len, in
evhtp_ssl_sess_t * sess;

connection = (evhtp_connection_t * )SSL_get_app_data(ssl);
if (connection->htp == NULL)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above. Should evhtp_unlikely be used here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as the other scache stuff; fairly certain it isn't even used. But I will doublecheck when I get home.

Copy link
Contributor Author

@sftwrngnr sftwrngnr left a comment

Choose a reason for hiding this comment

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

I had a couple of questions related to evhtp_likely/unlikely being used.

@NathanFrench NathanFrench merged commit 9650124 into Yellow-Camper:develop Nov 1, 2017
@NathanFrench NathanFrench added this to the v1.2.13 milestone Nov 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants