Skip to content

crypto/tls: make checkForResumption side-effect free#3

Open
SparrowLii wants to merge 1 commit intoMabinGo:masterfrom
SparrowLii:0727-tls
Open

crypto/tls: make checkForResumption side-effect free#3
SparrowLii wants to merge 1 commit intoMabinGo:masterfrom
SparrowLii:0727-tls

Conversation

@SparrowLii
Copy link
Copy Markdown

Fixes golang#39406
When use checkForResumption() function it could be side-effect sometime.

  1. hs.sessionState will be changed and retained although the function return false.
  2. hs.suite will be changed and retained when the statements below return false.
    So we should use a local variable, cilentSessionState, to replace hs.sessionState in the function. And move the set-suite statements down to avoid being changed too early.

This PR will be imported into Gerrit with the title and first
comment (this text) used to generate the subject and body of
the Gerrit change.

Please ensure you adhere to every item in this list.

More info can be found at https://github.com/golang/go/wiki/CommitMessage

  • The PR title is formatted as follows: net/http: frob the quux before blarfing
    • The package name goes before the colon
    • The part after the colon uses the verb tense + phrase that completes the blank in,
      "This change modifies Go to ___________"
    • Lowercase verb after the colon
    • No trailing period
    • Keep the title as short as possible. ideally under 76 characters or shorter
  • No Markdown
  • The first PR comment (this one) is wrapped at 76 characters, unless it's
    really needed (ASCII art, table, or long link)
  • If there is a corresponding issue, add either Fixes #1234 or Updates #1234
    (the latter if this is not a complete fix) to this comment
  • If referring to a repo other than golang/go you can use the
    owner/repo#issue_number syntax: Fixes golang/tools#1234
  • We do not use Signed-off-by lines in Go. Please don't add them.
    Our Gerrit server & GitHub bots enforce CLA compliance instead.
  • Delete these instructions once you have read and applied them

Fixes golang#39406
When use checkForResumption() function it could be side-effect sometime.
1. hs.sessionState will be changed and retained although the function return false.
2. hs.suite will be changed and retained when the statements below return false.
So  we should use a local variable, cilentSessionState, to replace hs.sessionState in the function. And move the set-suite statements down to avoid being changed too early.
return false
}

// Check that we also support the ciphersuite from the session.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

这里改动代码顺序有影响吗?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

有影响,这样做避免了给hs.suite赋值以后,之后的函数语句又返回了false结果,导致suite维护了一个无用的值。保持了函数的side-effect free。

}

// Check that we also support the ciphersuite from the session.
hs.suite = selectCipherSuite([]uint16{clientSessionState.cipherSuite},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

看起来似乎还是存在hs.suite被赋值,但是最终返回false的情况

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

这种情况下只可能是suite==nil,然后返回false,表示没有找到合适的加解密工具版本。suite之前就是nil,没有变化

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

Successfully merging this pull request may close these issues.

crypto/tls: cleanup handshake state

2 participants