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

Conditional jump on uninitialised value(s) in cws.c #900

Closed
davesliu opened this issue Sep 18, 2017 · 7 comments
Closed

Conditional jump on uninitialised value(s) in cws.c #900

davesliu opened this issue Sep 18, 2017 · 7 comments

Comments

@davesliu
Copy link
Contributor

The variables cws->peer_gone is not initialized in below piece of code in function nn_cws_handler of cws.c
//
/
STOPPING_USOCK state. /
/
usock object was asked to stop but it haven't stopped yet. /
/
/
case NN_CWS_STATE_STOPPING_USOCK:
switch (src) {

    case NN_CWS_SRC_USOCK:
        switch (type) {
        case NN_USOCK_SHUTDOWN:
            return;
        case NN_USOCK_STOPPED:
            /*  If the peer has confirmed itself gone with a Closing
                Handshake, or if the local endpoint failed the remote,
                don't try to reconnect. */
            if (!cws->peer_gone) {
                nn_backoff_start (&cws->retry);
                cws->state = NN_CWS_STATE_WAITING;
            }
            return;
        default:
            nn_fsm_bad_action (cws->state, src, type);
        }

    default:
        nn_fsm_bad_source (cws->state, src, type);
    }
@davesliu
Copy link
Contributor Author

BTW, there is no "break" for each "case" & "default" in this nn_cws_handler function.

@gdamore
Copy link
Contributor

gdamore commented Sep 18, 2017

The lack of a "break", is because the other cases "return", and default is the last case. There is no need for a break.

@gdamore
Copy link
Contributor

gdamore commented Sep 18, 2017

Good catch on the uninitialized variable, though. This should be cleared to zero after the cws structure is allocated.

@davesliu
Copy link
Contributor Author

if their is no “break”,the function nn_fsm_bad_action will be executed muti times....

@skyformat99
Copy link

nn_fsm_bad_action
nn_fsm_bad_source
These two functions are different。😄

@davesliu
Copy link
Contributor Author

@skyformat99
Sorry.
Yes, both the nn_fsm_bad_action & nn_fsm_bad_action will be executed ...

@gdamore
Copy link
Contributor

gdamore commented Oct 11, 2017

No, they won't -- because both of these call nn_fsm_error(), which aborts the program; these conditions are never supposed to arrive, and this is effectively an assertion that they do not.

See src/utils/err.h for details.

@gdamore gdamore changed the title Conditional jump on uninitialised value(s) in function nn_cws_handler of cws.c Conditional jump on uninitialised value(s) in cws.c Oct 11, 2017
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

3 participants