Skip to content

Commit

Permalink
Fix buffer-overrun bug in net (#17728) [backport:1.0]
Browse files Browse the repository at this point in the history
(cherry picked from commit fdd4391)
  • Loading branch information
shirleyquirk authored and narimiran committed Aug 24, 2021
1 parent 286b94e commit e5a3f30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@


## Library additions
- Fixed buffer overflow bugs in `net`

- Added `sections` iterator in `parsecfg`.

- Added `browsers.osOpen` const alias for the operating system specific *"open"* command.

Expand Down
7 changes: 3 additions & 4 deletions lib/pure/net.nim
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,11 @@ when defineSsl:
let ctx = SslContext(context: ssl.SSL_get_SSL_CTX)
let hintString = if hint == nil: "" else: $hint
let (identityString, pskString) = (ctx.clientGetPskFunc)(hintString)
if psk.len.cuint > max_psk_len:
if pskString.len.cuint > max_psk_len:
return 0
if identityString.len.cuint >= max_identity_len:
return 0

copyMem(identity, identityString.cstring, pskString.len + 1) # with the last zero byte
copyMem(identity, identityString.cstring, identityString.len + 1) # with the last zero byte
copyMem(psk, pskString.cstring, pskString.len)

return pskString.len.cuint
Expand All @@ -624,7 +623,7 @@ when defineSsl:
max_psk_len: cint): cuint {.cdecl.} =
let ctx = SslContext(context: ssl.SSL_get_SSL_CTX)
let pskString = (ctx.serverGetPskFunc)($identity)
if psk.len.cint > max_psk_len:
if pskString.len.cint > max_psk_len:
return 0
copyMem(psk, pskString.cstring, pskString.len)

Expand Down

0 comments on commit e5a3f30

Please sign in to comment.