Skip to contentSkip to conversation

stubdom: Fix GCC 14 -Wmemset-elt-size compiler warnings in PolarSSL

PATCH Superseded Andrew Mbugua 3 participants 6 messages Aug 25 – Sep 10

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 stubdom: Fix GCC 14 -Wmemset-elt-size compiler warnings in PolarSSL

When compiling Xen with GCC 14, I get a compiler warning originating from the /polarssl-x86_64/library about a memset element size mismatch:

ssl_tls.c: In function ‘ssl_session_reset’:
ssl_tls.c:1778:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1778 | memset( ssl->ctx_enc, 0, 128 );
| ^~~~~~
ssl_tls.c:1779:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1779 | memset( ssl->ctx_dec, 0, 128 );
| ^~~~~~

This patch introduces a build-time patch to PolarSSL that replaces the hardcoded 128 byte length with a dynamic sizeof(), thus allowing clean compilation without warnings.

---
 stubdom/patches/polarssl-gcc14-memset.patch | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 stubdom/patches/polarssl-gcc14-memset.patch
stubdom/patches/polarssl-gcc14-memset.patch new file +13 -0
new file mode 100644
index 0000000000..d98664d0a8
@@ -0,0 +1,13 @@
+--- a/library/ssl_tls.c
++++ b/library/ssl_tls.c
+@@ -1775,8 +1775,8 @@
+     memset( ssl->iv_dec, 0, 16 );
+     memset( ssl->mac_enc, 0, 32 );
+     memset( ssl->mac_dec, 0, 32 );
+-    memset( ssl->ctx_enc, 0, 128 );
+-    memset( ssl->ctx_dec, 0, 128 );
++    memset( ssl->ctx_enc, 0, sizeof( *ssl->ctx_enc) );
++    memset( ssl->ctx_dec, 0, sizeof( *ssl->ctx_dec) );
+ 
+      md5_starts( &ssl->fin_md5  );
+     sha1_starts( &ssl->fin_sha1 );
Signature · 1 line
2.47.3
#1 lore raw
Quoted 11 lines · Andrew Mbugua

When compiling Xen with GCC 14, I get a compiler warning originating from the /polarssl-x86_64/library about a memset element size mismatch:

ssl_tls.c: In function ‘ssl_session_reset’:
ssl_tls.c:1778:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1778 | memset( ssl->ctx_enc, 0, 128 );
| ^~~~~~
ssl_tls.c:1779:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1779 | memset( ssl->ctx_dec, 0, 128 );
| ^~~~~~

This patch introduces a build-time patch to PolarSSL that replaces the hardcoded 128 byte length with a dynamic sizeof(), thus allowing clean compilation without warnings.

First a formal note: Commit messages want limiting to 75 characters per line (some even say 72).

Then: You introduce a patch which isn't used anywhere. What use is such a patch? You also ...

Quoted 5 lines
---
 stubdom/patches/polarssl-gcc14-memset.patch | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 stubdom/patches/polarssl-gcc14-memset.patch

... introduce it in a new patches/ subdir, when all other patches live right beneath stubdom/.

stubdom/patches/polarssl-gcc14-memset.patch line 10

Quoted 13 lines
stubdom/patches/polarssl-gcc14-memset.patch new file +10 -0
@@ -0,0 +1,13 @@
+--- a/library/ssl_tls.c
++++ b/library/ssl_tls.c
+@@ -1775,8 +1775,8 @@
+     memset( ssl->iv_dec, 0, 16 );
+     memset( ssl->mac_enc, 0, 32 );
+     memset( ssl->mac_dec, 0, 32 );
+-    memset( ssl->ctx_enc, 0, 128 );
+-    memset( ssl->ctx_dec, 0, 128 );
++    memset( ssl->ctx_enc, 0, sizeof( *ssl->ctx_enc) );
++    memset( ssl->ctx_dec, 0, sizeof( *ssl->ctx_dec) );

Don't you mean sizeof(ssl->ctx_enc) and sizeof(ssl->ctx_dec) respectively? Otherwise it looks like you're making a bad situation worse.

Judging from surrounding style, there also looks to be a blank missing each, ahead of the new inner closing parenthesis.

Jan

#2 lore raw

I was at first deliberating whether to send further patches because the current successor of PolarSSL is MbedTLS. Polarssl is now legacy & not maintained(polarssl was acquired by ARM).
Options:
1. Continual patching/maintaining a legacy library.
2. Upgrade to MbedTLS which will require alot of API changes.

Quoted 56 lines · Jan Beulich
Quoted 1 line · Andrew Mbugua

When compiling Xen with GCC 14, I get a compiler warning originating

from the /polarssl-x86_64/library about a memset element size mismatch:

Quoted 3 lines

ssl_tls.c: In function ‘ssl_session_reset’:
ssl_tls.c:1778:5: warning: ‘memset’ used with length equal to number of

elements without multiplication by element size [-Wmemset-elt-size]

Quoted 3 lines

1778 | memset( ssl->ctx_enc, 0, 128 );
| ^~~~~~
ssl_tls.c:1779:5: warning: ‘memset’ used with length equal to number of

elements without multiplication by element size [-Wmemset-elt-size]

Quoted 4 lines

1779 | memset( ssl->ctx_dec, 0, 128 );
| ^~~~~~

This patch introduces a build-time patch to PolarSSL that replaces the

hardcoded 128 byte length with a dynamic sizeof(), thus allowing clean compilation without warnings.

First a formal note: Commit messages want limiting to 75 characters per line (some even say 72).

Then: You introduce a patch which isn't used anywhere. What use is such a patch? You also ...

Quoted 5 lines
---
 stubdom/patches/polarssl-gcc14-memset.patch | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 stubdom/patches/polarssl-gcc14-memset.patch

... introduce it in a new patches/ subdir, when all other patches live right beneath stubdom/.

stubdom/patches/polarssl-gcc14-memset.patch line 10

Quoted 13 lines
stubdom/patches/polarssl-gcc14-memset.patch new file +10 -0
@@ -0,0 +1,13 @@
+--- a/library/ssl_tls.c
++++ b/library/ssl_tls.c
+@@ -1775,8 +1775,8 @@
+     memset( ssl->iv_dec, 0, 16 );
+     memset( ssl->mac_enc, 0, 32 );
+     memset( ssl->mac_dec, 0, 32 );
+-    memset( ssl->ctx_enc, 0, 128 );
+-    memset( ssl->ctx_dec, 0, 128 );
++    memset( ssl->ctx_enc, 0, sizeof( *ssl->ctx_enc) );
++    memset( ssl->ctx_dec, 0, sizeof( *ssl->ctx_dec) );

Don't you mean sizeof(ssl->ctx_enc) and sizeof(ssl->ctx_dec) respectively? Otherwise it looks like you're making a bad situation worse.

Judging from surrounding style, there also looks to be a blank missing each,
ahead of the new inner closing parenthesis.

Jan

#3 lore raw
Quoted 3 lines · Andrew Precious

I was at first deliberating whether to send further patches because the current successor of PolarSSL is MbedTLS. Polarssl is now legacy & not maintained(polarssl was acquired by ARM). Options:
1. Continual patching/maintaining a legacy library.

This one.

Main reason is that there are more modern alternatives to Mini-OS, e.g. UNIKRAFT. We don't want to do a big rework of the Xen stubdom environment.

Juergen

#4 lore raw

PATCH v2 1/1 stubdom: Fix GCC 14 -Wmemset-elt-size compiler warnings in PolarSSL

A followup to the email thread with the previously suggested changes.

I have:
1. Added the patch reference to the Makefile
2. Removed the new subdirectory I created.
3. Formatted patch message to be <75 characters per line

When compiling Xen with GCC 14, I get a compiler warning originating from the /polarssl-x86_64/library about a memset element size mismatch:

ssl_tls.c: In function ‘ssl_session_reset’:
ssl_tls.c:1778:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1778 | memset( ssl->ctx_enc, 0, 128 );
| ^~~~~~
ssl_tls.c:1779:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1779 | memset( ssl->ctx_dec, 0, 128 );
| ^~~~~~

This patch introduces a build-time patch to PolarSSL that replaces the hardcoded 128 byte length with sizeof() allowing clean compilation without warnings.

---
 stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch
stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch new file +13 -0
new file mode 100644
index 0000000000..3528f2817a
@@ -0,0 +1,13 @@
+--- a/library/ssl_tls.c
++++ b/library/ssl_tls.c
+@@ -1775,8 +1775,8 @@
+ 	memset( ssl->iv_dec, 0, 16 );
+ 	memset( ssl->mac_enc, 0, 32 );
+ 	memset( ssl->mac_dec, 0, 32 );
+-    memset( ssl->ctx_enc, 0, 128 );
+-    memset( ssl->ctx_dec, 0, 128 );
++    memset( ssl->ctx_enc, 0, sizeof( ssl->ctx_enc ) );
++    memset( ssl->ctx_dec, 0, sizeof( ssl->ctx_dec ) );
+ 
+ 	md5_starts( &ssl->fin_md5  );
+ 	sha1_starts( &ssl->fin_sha1 );
Signature · 1 line
2.47.3
#5 lore raw
Quoted 6 lines · Andrew Mbugua

A followup to the email thread with the previously suggested changes.

I have:
1. Added the patch reference to the Makefile
2. Removed the new subdirectory I created.
3. Formatted patch message to be <75 characters per line

For one, none of the above should be part of the commit message. Such wants to move past the first --- separator.

Then: While I see you did 2, I don't think you really did 1 and 3. As to 3,
...

Quoted 1 line

When compiling Xen with GCC 14, I get a compiler warning originating from the /polarssl-x86_64/library about a memset element size mismatch:

... this is still in need of wrapping, whereas ...

Quoted 7 lines

ssl_tls.c: In function ‘ssl_session_reset’:
ssl_tls.c:1778:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1778 | memset( ssl->ctx_enc, 0, 128 );
| ^~~~~~
ssl_tls.c:1779:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1779 | memset( ssl->ctx_dec, 0, 128 );
| ^~~~~~

... compiler output may be kept as is (imo).

Quoted 2 lines

This patch introduces a build-time patch to PolarSSL that replaces the hardcoded 128 byte length with sizeof() allowing clean compilation without warnings.

This again looks to need suitable wrapping. Furthermore, isn't there a little more to be said here? After all sizeof(ssl->ctx_enc) != 128, afaict.

Quoted 5 lines
---
 stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch

In line with other patches we have there, maybe better name this e.g. polarssl-gcc14.patch?

Quoted 6 lines
stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch new file +3 -0
@@ -0,0 +1,13 @@
+--- a/library/ssl_tls.c
++++ b/library/ssl_tls.c
+@@ -1775,8 +1775,8 @@

stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch line 13

Quoted 10 lines
stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch new file +10 -0
+ 	memset( ssl->iv_dec, 0, 16 );
+ 	memset( ssl->mac_enc, 0, 32 );
+ 	memset( ssl->mac_dec, 0, 32 );
+-    memset( ssl->ctx_enc, 0, 128 );
+-    memset( ssl->ctx_dec, 0, 128 );
++    memset( ssl->ctx_enc, 0, sizeof( ssl->ctx_enc ) );
++    memset( ssl->ctx_dec, 0, sizeof( ssl->ctx_dec ) );
+ 
+ 	md5_starts( &ssl->fin_md5  );
+ 	sha1_starts( &ssl->fin_sha1 );

I haven't tried it out, but I can't help the impression that this patch is not going to apply. The source code I'm looking at has no use of hard tabs, yet there are hard tabs on the patch context lines above (yet interestingly not on the lines actually altered).

Jan