Skip to contentSkip to conversation

auth_token_kt: ensure key_type object is initialized

PATCH In review Antonio Quartulli 4 participants 17 messages Nov 10, 2019 – Nov 11, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 auth_token_kt: ensure key_type object is initialized

Fixes the following warning:

auth_token.c: In function 'auth_token_init_secret':
auth_token.c:47: warning: 'kt.cipher_length' is used uninitialized in this function auth_token.c:34: note: 'kt.cipher_length' was declared here

---
 src/openvpn/auth_token.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/auth_token.c +1 -1
index 1edc8069..6275299d 100644
@@ -31,7 +31,7 @@ const char *auth_token_pem_name = "OpenVPN auth-token server key";
 static struct key_type
 auth_token_kt(void)
 {
-    struct key_type kt;
+    struct key_type kt = { 0 };
     /* We do not encrypt our session tokens */
     kt.cipher = NULL;
     kt.digest = md_kt_get("SHA256");
Signature · 1 line
2.24.0
#1 lore raw

PATCH 2/3 auth.c: make cast explicit in the crypto API

mbedtls_md_get_size() returns unsigned char, while EVP_MD_size() returns int. Results coming from both functions are normally in a uint8_t member of the key_type struct, because it is known that 8bits are enough (also for EVP_MD_size()).

This unexpected cast can, however, trigger unsolicited warnings. Make the cast explicit by changing the return value of our crypto API.

---
 src/openvpn/crypto_backend.h | 2 +-
 src/openvpn/crypto_mbedtls.c | 2 +-
 src/openvpn/crypto_openssl.c | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
src/openvpn/crypto_backend.h +1 -1
index d119442f..1d206a8c 100644
@@ -526,7 +526,7 @@ const char *md_kt_name(const md_kt_t *kt);
  *
  * @return              Message digest size, in bytes, or 0 if ctx was NULL.
  */
-int md_kt_size(const md_kt_t *kt);
+unsigned char md_kt_size(const md_kt_t *kt);
 
 
 /*
src/openvpn/crypto_mbedtls.c +1 -1
index 648a988e..3e77fa9e 100644
@@ -823,7 +823,7 @@ md_kt_name(const mbedtls_md_info_t *kt)
     return mbedtls_md_get_name(kt);
 }
 
-int
+unsigned char
 md_kt_size(const mbedtls_md_info_t *kt)
 {
     if (NULL == kt)
src/openvpn/crypto_openssl.c +2 -2
index 520e40ee..a81dcfd8 100644
@@ -930,10 +930,10 @@ md_kt_name(const EVP_MD *kt)
     return EVP_MD_name(kt);
 }
 
-int
+unsigned char
 md_kt_size(const EVP_MD *kt)
 {
-    return EVP_MD_size(kt);
+    return (unsigned char)EVP_MD_size(kt);
 }
 
 
Signature · 1 line
2.24.0
Acked-by on v1 2/3
#2 lore raw

Re: [Openvpn-devel] [PATCH 2/3] auth.c: make cast explicit in the crypto API

Am 10.11.19 um 14:35 schrieb Antonio Quartulli:

Quoted 8 lines

mbedtls_md_get_size() returns unsigned char, while EVP_MD_size() returns int. Results coming from both functions are normally in a uint8_t member of the key_type struct, because it is known that 8bits are enough (also for EVP_MD_size()).

This unexpected cast can, however, trigger unsolicited warnings. Make the cast explicit by changing the return value of our crypto API.

Not sure that this really needed but it also does not hurt, so

Arne

#3 lore raw

[Openvpn-devel] [PATCH applied] Re: auth.c: make cast explicit in the crypto API

In reply to Antonio Quartulli

Your patch has been applied to the master branch.

commit 7122af670d58586d9806214c81d27c424b226730

Author: Antonio Quartulli
Date:   Sun Nov 10 14:35:24 2019 +0100
     auth.c: make cast explicit in the crypto API

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19093.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#4 lore raw

[Openvpn-devel] [PATCH applied] Re: auth.c: make cast explicit in the crypto API

In reply to Antonio Quartulli

Your patch has been applied to the master branch.

(Resending with correct "Acked-by" line - I noticed after I sent the mail but before pushing, so I amended the commit and here's the right ID)

commit 6c7b41c6536b221b1e2bc26a26ae6814a71d69e8

Author: Antonio Quartulli
Date:   Sun Nov 10 14:35:24 2019 +0100
     auth.c: make cast explicit in the crypto API

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19093.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw

[Openvpn-devel] [PATCH applied] Re: auth.c: make cast explicit in the crypto API

In reply to Antonio Quartulli

Your patch has been applied to the master branch.

(Resending with correct "Acked-by" line - I noticed after I sent the mail but before pushing, so I amended the commit and here's the right ID)

commit 6c7b41c6536b221b1e2bc26a26ae6814a71d69e8

Author: Antonio Quartulli
Date:   Sun Nov 10 14:35:24 2019 +0100
     auth.c: make cast explicit in the crypto API

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19093.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw

PATCH 3/3 travis: compile with -Werror on Linux

In reply to Antonio Quartulli
---
 .travis/build-check.sh | 1 +
 1 file changed, 1 insertion(+)
.travis/build-check.sh +1 -0
index 039a7dcf..250bb454 100755
@@ -8,6 +8,7 @@ fi
 
 if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
 	export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH:-}"
+	export CFLAGS="${CFLAGS} -Werror"
 fi
 
 if [ "${TRAVIS_OS_NAME}" = "osx"   ]; then
Signature · 1 line
2.24.0
Acked-by on v1 3/3
#7 lore raw

Re: [Openvpn-devel] [PATCH 3/3] travis: compile with -Werror on Linux

Am 10.11.19 um 14:35 schrieb Antonio Quartulli:

Quoted 11 lines
---
 .travis/build-check.sh | 1 +
 1 file changed, 1 insertion(+)
.travis/build-check.sh +0 -0
index 039a7dcf..250bb454 100755

.travis/build-check.sh fi · line 14

Quoted 7 lines
.travis/build-check.sh +1 -0
@@ -8,6 +8,7 @@ fi
 
 if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
 	export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH:-}"
+	export CFLAGS="${CFLAGS} -Werror"
 fi
 
 if [ "${TRAVIS_OS_NAME}" = "osx"   ]; then

I assume that you compile tested this, so

#8 lore raw

Re: [Openvpn-devel] [PATCH 3/3] travis: compile with -Werror on Linux

In reply to Antonio Quartulli

Hi,

Quoted 10 lines · Antonio Quartulli
---
 .travis/build-check.sh | 1 +
 1 file changed, 1 insertion(+)
.travis/build-check.sh +0 -0
index 039a7dcf..250bb454 100755

.travis/build-check.sh fi · line 13

Quoted 6 lines
.travis/build-check.sh +1 -0
@@ -8,6 +8,7 @@ fi
 
 if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
        export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH:-}"
+       export CFLAGS="${CFLAGS} -Werror"
 fi
 

If this is only for linux (and travis), and works with the current code base, probably its fine.

But it seems it may also affect mingw builds on travis. I would resist the temptation to add -Werror in general and to Windows cross-build in particular.

Not all warnings can be fixed easily. Often the only option is to hide the warning (e.g, by adding a cast) which imo is not always a good strategy. -Werror just forces one's hand to use tricks that hide warnings.

Selva

#9 lore raw

Re: [Openvpn-devel] [PATCH 3/3] travis: compile with -Werror on Linux

Hi,

Quoted 3 lines · Selva Nair

But it seems it may also affect mingw builds on travis. I would resist the temptation to add -Werror in general and to Windows cross-build in particular.

Yeah, we're not intending to.

The plan is to have "default builds (no configure options) on Linux with sufficiently current C compilers" warning-free. Which can be achieved with the current code base.

Quoted 3 lines

Not all warnings can be fixed easily. Often the only option is to hide the warning (e.g, by adding a cast) which imo is not always a good strategy. -Werror just forces one's hand to use tricks that hide warnings.

Right. Older systems will warn, oddball systems will warn, non-default build options will warn (and I take one "unused global variable" warning vs. "adding two lines #ifdef/#endif").

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#10 lore raw

Re: [Openvpn-devel] [PATCH 3/3] travis: compile with -Werror on Linux

Forgot to hit send on this, and probably this is only partially relevant now, but here goes.

Hi

Quoted 10 lines · Gert Doering

Hi,

Quoted 1 line · Selva Nair

But it seems it may also affect mingw builds on travis. I would resist

the

Quoted 2 lines

temptation to add -Werror in general and to Windows cross-build in particular.

Yeah, we're not intending to.

But the patch does affect cross-compilation for Windows on linux.

Unless restricted to a very small cross-section (say gcc x.y + linux) this is going to cause a lot of grief. Note that every check run by configure that succeeds with warnings will become mysterious error at build time. There may be other unexpected failures too. -Werror is never fit for production in my view. There is a reason why warnings are warnings.

Just my 2c.

Selva

#11 lore raw

Re: [Openvpn-devel] [PATCH 3/3] travis: compile with -Werror on Linux

Hi,

Quoted 7 lines · Selva Nair
Quoted 5 lines

the

Quoted 2 lines

temptation to add -Werror in general and to Windows cross-build in particular.

Yeah, we're not intending to.

But the patch does affect cross-compilation for Windows on linux.

That seems to have been an oversight in how to feed Travis what we want - I saw an update yesterday evening.

Quoted 5 lines

Unless restricted to a very small cross-section (say gcc x.y + linux) this is going to cause a lot of grief. Note that every check run by configure that succeeds with warnings will become mysterious error at build time. There may be other unexpected failures too. -Werror is never fit for production in my view. There is a reason why warnings are warnings.

"gcc $current + linux" was the plan, and only do it in Travis, not do it in configure for general consumption.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#12 lore raw

Re: [Openvpn-devel] [PATCH 3/3] travis: compile with -Werror on Linux

Hi,

Quoted 5 lines · Gert Doering
Quoted 1 line

But the patch does affect cross-compilation for Windows on linux.

That seems to have been an oversight in how to feed Travis what we want - I saw an update yesterday evening.

Quoted 9 lines
Quoted 5 lines

Unless restricted to a very small cross-section (say gcc x.y + linux) this is going to cause a lot of grief. Note that every check run by configure that succeeds with warnings will become mysterious error at build time. There may be other unexpected failures too. -Werror is never fit for production in my view. There is a reason why warnings are warnings.

"gcc $current + linux" was the plan, and only do it in Travis, not do it in configure for general consumption.

Right - this was my mistake while creating this patch.
A fix has been sent to the ml yesterday night. That should work as expected.

However, note that Travis won't be 100% happy because some compilers don't have the -Wno-stringop-truncation we recently added and configure.ac is failing to detect that....

Cheers,

Signature · 1 line
Antonio Quartulli
#13 lore raw

[Openvpn-devel] [PATCH applied] Re: travis: compile with -Werror on Linux

In reply to Antonio Quartulli

Your patch has been applied to the master branch.

commit 1513489be632f6577021e3a0f51799b59c4ace6a

Author: Antonio Quartulli
Date:   Sun Nov 10 14:35:25 2019 +0100
     travis: compile with -Werror on Linux

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19094.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 1/3
#14 lore raw
In reply to Antonio Quartulli

Am 10.11.19 um 14:35 schrieb Antonio Quartulli:

Quoted 18 lines

Fixes the following warning:

auth_token.c: In function 'auth_token_init_secret':
auth_token.c:47: warning: 'kt.cipher_length' is used uninitialized in this function auth_token.c:34: note: 'kt.cipher_length' was declared here

---
 src/openvpn/auth_token.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/auth_token.c +0 -0
index 1edc8069..6275299d 100644

src/openvpn/auth_token.c const char *auth_token_pem_name = "OpenVPN auth-token server key"; · line 37

Quoted 8 lines
src/openvpn/auth_token.c +1 -1
@@ -31,7 +31,7 @@ const char *auth_token_pem_name = "OpenVPN auth-token server key";
 static struct key_type
 auth_token_kt(void)
 {
-    struct key_type kt;
+    struct key_type kt = { 0 };
     /* We do not encrypt our session tokens */
     kt.cipher = NULL;
     kt.digest = md_kt_get("SHA256");

Arne

#15 lore raw
In reply to Antonio Quartulli

Your patch has been applied to the master branch.

commit 9c380048a36cd1d1565607b5a0bee0ebbb8b1465

Author: Antonio Quartulli
Date:   Sun Nov 10 14:35:23 2019 +0100
     auth_token_kt: ensure key_type object is initialized

     Signed-off-by: Arne Schwabe <[email protected]...>
     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19092.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#16 lore raw
In reply to Antonio Quartulli

Your patch has been applied to the master branch.

(Resent with correct Acked-By:)

commit 9d0b95c45130af2f91fa2195c483e2c7461c0f40

Author: Antonio Quartulli
Date:   Sun Nov 10 14:35:23 2019 +0100
     auth_token_kt: ensure key_type object is initialized

     Signed-off-by: Arne Schwabe <[email protected]...>
     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19092.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering