From 0299652066fe3d2b130e1ae33f1a806f4a02c162 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 17:23:23 +0200 Subject: [PATCH 01/12] make cuchar uint8 --- lib/system.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system.nim b/lib/system.nim index 6e84aca667b4..62f335e1ee57 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1444,7 +1444,7 @@ type # these work for most platforms: ## This is the same as the type `long double` in *C*. ## This C type is not supported by Nim's code generator. - cuchar* {.importc: "unsigned char", nodecl.} = char + cuchar* {.importc: "unsigned char", nodecl.} = uint8 ## This is the same as the type `unsigned char` in *C*. cushort* {.importc: "unsigned short", nodecl.} = uint16 ## This is the same as the type `unsigned short` in *C*. From 4b83054a9f0a8b6f4a635a0206b774f1bc70818b Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 18:30:53 +0200 Subject: [PATCH 02/12] changing cuchar highlighted a buffer-overrun in net --- lib/pure/net.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 9be9c6acbf11..12bf5a8d49a3 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -690,12 +690,12 @@ 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: - return 0 if identityString.len.cuint >= max_identity_len: return 0 - + if pskString.len.cuint > max_psk_len: + return 0 copyMem(identity, identityString.cstring, pskString.len + 1) # with the last zero byte + copyMem(psk, pskString.cstring, pskString.len) return pskString.len.cuint @@ -716,7 +716,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) From f2690dbf1a48266d17f4dc844fe2d7ad526b4798 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 18:33:58 +0200 Subject: [PATCH 03/12] ocd --- lib/pure/net.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 12bf5a8d49a3..df333e3038c6 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -690,12 +690,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 identityString.len.cuint >= max_identity_len: - return 0 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(psk, pskString.cstring, pskString.len) return pskString.len.cuint From 94a9e0d2bb71bdf96a01fbf03b1730e96fe8a5d1 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 20:33:26 +0200 Subject: [PATCH 04/12] yikes --- lib/pure/net.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/net.nim b/lib/pure/net.nim index df333e3038c6..343cdc9b1b77 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -694,7 +694,7 @@ when defineSsl: 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 From 4f72a21a2972142903c6b4089156447a508f5b23 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 21:00:04 +0200 Subject: [PATCH 05/12] changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 2f1d2d816f24..1463c9bfec10 100644 --- a/changelog.md +++ b/changelog.md @@ -37,6 +37,7 @@ unless `-d:nimLegacyHomeDir` is specified (for a transition period). ## Standard library additions and changes +- Fixed buffer overflow bugs in `net` - Added `sections` iterator in `parsecfg`. From 8947b37ac7f5d539e7c7a097f2b00bf2ae372d77 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 21:12:02 +0200 Subject: [PATCH 06/12] sorry, ok that should be a separate pr --- changelog.md | 2 ++ changelogs/changelog_X_XX_X.md | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 1463c9bfec10..b3ba4fddbe5a 100644 --- a/changelog.md +++ b/changelog.md @@ -37,6 +37,8 @@ unless `-d:nimLegacyHomeDir` is specified (for a transition period). ## Standard library additions and changes +- Added support for parenthesised expressions in strformat + - Fixed buffer overflow bugs in `net` - Added `sections` iterator in `parsecfg`. diff --git a/changelogs/changelog_X_XX_X.md b/changelogs/changelog_X_XX_X.md index d68ef4c208ce..524599b11983 100644 --- a/changelogs/changelog_X_XX_X.md +++ b/changelogs/changelog_X_XX_X.md @@ -13,8 +13,6 @@ The changes should go to changelog.md! - Changed `example.foo` to take additional `bar` parameter. -- Added support for evaluating parenthesised expressions in strformat - ## Language changes From 1aab7001dd21386498b79a8b1af368178c774069 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 21:26:05 +0200 Subject: [PATCH 07/12] i can't git --- changelog.md | 2 -- changelogs/changelog_X_XX_X.md | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index b3ba4fddbe5a..1463c9bfec10 100644 --- a/changelog.md +++ b/changelog.md @@ -37,8 +37,6 @@ unless `-d:nimLegacyHomeDir` is specified (for a transition period). ## Standard library additions and changes -- Added support for parenthesised expressions in strformat - - Fixed buffer overflow bugs in `net` - Added `sections` iterator in `parsecfg`. diff --git a/changelogs/changelog_X_XX_X.md b/changelogs/changelog_X_XX_X.md index 524599b11983..d68ef4c208ce 100644 --- a/changelogs/changelog_X_XX_X.md +++ b/changelogs/changelog_X_XX_X.md @@ -13,6 +13,8 @@ The changes should go to changelog.md! - Changed `example.foo` to take additional `bar` parameter. +- Added support for evaluating parenthesised expressions in strformat + ## Language changes From 644b4bd094a28f8dd630b1649dec905a12fe1d7b Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 21:51:22 +0200 Subject: [PATCH 08/12] cuchar change --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index 1463c9bfec10..d7eb875ff4ed 100644 --- a/changelog.md +++ b/changelog.md @@ -37,6 +37,8 @@ unless `-d:nimLegacyHomeDir` is specified (for a transition period). ## Standard library additions and changes +- `cuchar` now maps to `int8` instead of `char` + - Fixed buffer overflow bugs in `net` - Added `sections` iterator in `parsecfg`. From 9b5a14826e1cb6d685f9c83c597f9c4e8d5c217d Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 21:52:47 +0200 Subject: [PATCH 09/12] u --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index d7eb875ff4ed..8afd9f162346 100644 --- a/changelog.md +++ b/changelog.md @@ -37,7 +37,7 @@ unless `-d:nimLegacyHomeDir` is specified (for a transition period). ## Standard library additions and changes -- `cuchar` now maps to `int8` instead of `char` +- `cuchar` now maps to `uint8` instead of `char` - Fixed buffer overflow bugs in `net` From fb72b7f388e2c76eb9b2ee4995c3e05359436509 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 21:54:28 +0200 Subject: [PATCH 10/12] s/map/aliases --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 8afd9f162346..7ab40632a40f 100644 --- a/changelog.md +++ b/changelog.md @@ -37,7 +37,7 @@ unless `-d:nimLegacyHomeDir` is specified (for a transition period). ## Standard library additions and changes -- `cuchar` now maps to `uint8` instead of `char` +- `cuchar` now aliases `uint8` instead of `char` - Fixed buffer overflow bugs in `net` From 3004924c5be9f30b808919d6ad35ac19c20e6758 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Thu, 15 Apr 2021 22:46:57 +0200 Subject: [PATCH 11/12] backward compat --- changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 7ab40632a40f..c07e7862145b 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,8 @@ ## Changes affecting backward compatibility +- `cuchar` now aliases `uint8` instead of `char` + - `repr` now doesn't insert trailing newline; previous behavior was very inconsistent, see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior. @@ -37,7 +39,6 @@ unless `-d:nimLegacyHomeDir` is specified (for a transition period). ## Standard library additions and changes -- `cuchar` now aliases `uint8` instead of `char` - Fixed buffer overflow bugs in `net` From 0a48546be5837d77b8ede0a9579d8e201028af92 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Fri, 16 Apr 2021 12:56:51 +0200 Subject: [PATCH 12/12] make backportable --- changelog.md | 2 -- lib/system.nim | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index c07e7862145b..4bfb33ba80cc 100644 --- a/changelog.md +++ b/changelog.md @@ -4,8 +4,6 @@ ## Changes affecting backward compatibility -- `cuchar` now aliases `uint8` instead of `char` - - `repr` now doesn't insert trailing newline; previous behavior was very inconsistent, see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior. diff --git a/lib/system.nim b/lib/system.nim index 62f335e1ee57..6e84aca667b4 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1444,7 +1444,7 @@ type # these work for most platforms: ## This is the same as the type `long double` in *C*. ## This C type is not supported by Nim's code generator. - cuchar* {.importc: "unsigned char", nodecl.} = uint8 + cuchar* {.importc: "unsigned char", nodecl.} = char ## This is the same as the type `unsigned char` in *C*. cushort* {.importc: "unsigned short", nodecl.} = uint16 ## This is the same as the type `unsigned short` in *C*.