From 7c5e790091b923db60aec82e777c28ef8aaf4dc3 Mon Sep 17 00:00:00 2001 From: noxpardalis <25850842+noxpardalis@users.noreply.github.com> Date: Wed, 30 Aug 2023 12:40:32 +0200 Subject: [PATCH] Resolve `snprintf` buffer overflow under GCC 12.3.0 (#1817) * ddsi_config: Fix buffer overflow for snprintf under GCC 12.3.0 * ddsi_config: Update generated files --- docs/manual/config/config_file_reference.rst | 2 +- docs/manual/options.md | 2 +- etc/cyclonedds.rnc | 2 +- etc/cyclonedds.xsd | 2 +- src/core/ddsi/defconfig.c | 2 +- src/core/ddsi/src/ddsi_config.c | 13 +++++++++---- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/manual/config/config_file_reference.rst b/docs/manual/config/config_file_reference.rst index 3673381593..669bb04e59 100644 --- a/docs/manual/config/config_file_reference.rst +++ b/docs/manual/config/config_file_reference.rst @@ -2637,7 +2637,7 @@ The default value is: ``none`` generated from ddsi_config.h[7f55b8f40b2e7f5984106abb0470128eb3d50017] generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] generated from ddsi__cfgelems.h[771184755c23b94599f2ffd6e8c242dcea7d2658] - generated from ddsi_config.c[5fc66f7b1f6542abb49c8fc129f47873bb3b9077] + generated from ddsi_config.c[1b4f1a011d558f331b8a547fd29ab473d0d926d5] generated from _confgen.h[1b1d88a85bd851f4e87118505ded33f7b33b0435] generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] diff --git a/docs/manual/options.md b/docs/manual/options.md index 9e303f3bd3..ec074e41b9 100644 --- a/docs/manual/options.md +++ b/docs/manual/options.md @@ -1849,7 +1849,7 @@ The default value is: `none` - + diff --git a/etc/cyclonedds.rnc b/etc/cyclonedds.rnc index e62b2309a0..a201755f67 100644 --- a/etc/cyclonedds.rnc +++ b/etc/cyclonedds.rnc @@ -1283,7 +1283,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==
# generated from ddsi_config.h[7f55b8f40b2e7f5984106abb0470128eb3d50017] # generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] # generated from ddsi__cfgelems.h[771184755c23b94599f2ffd6e8c242dcea7d2658] -# generated from ddsi_config.c[5fc66f7b1f6542abb49c8fc129f47873bb3b9077] +# generated from ddsi_config.c[1b4f1a011d558f331b8a547fd29ab473d0d926d5] # generated from _confgen.h[1b1d88a85bd851f4e87118505ded33f7b33b0435] # generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] # generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] diff --git a/etc/cyclonedds.xsd b/etc/cyclonedds.xsd index 15d3e4e5e3..314e3de98f 100644 --- a/etc/cyclonedds.xsd +++ b/etc/cyclonedds.xsd @@ -1950,7 +1950,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==<br> - + diff --git a/src/core/ddsi/defconfig.c b/src/core/ddsi/defconfig.c index 264c61f2fc..f64c13c674 100644 --- a/src/core/ddsi/defconfig.c +++ b/src/core/ddsi/defconfig.c @@ -106,7 +106,7 @@ void ddsi_config_init_default (struct ddsi_config *cfg) /* generated from ddsi_config.h[7f55b8f40b2e7f5984106abb0470128eb3d50017] */ /* generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] */ /* generated from ddsi__cfgelems.h[771184755c23b94599f2ffd6e8c242dcea7d2658] */ -/* generated from ddsi_config.c[5fc66f7b1f6542abb49c8fc129f47873bb3b9077] */ +/* generated from ddsi_config.c[1b4f1a011d558f331b8a547fd29ab473d0d926d5] */ /* generated from _confgen.h[1b1d88a85bd851f4e87118505ded33f7b33b0435] */ /* generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] */ /* generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] */ diff --git a/src/core/ddsi/src/ddsi_config.c b/src/core/ddsi/src/ddsi_config.c index e66afea36f..71dbf22eaf 100644 --- a/src/core/ddsi/src/ddsi_config.c +++ b/src/core/ddsi/src/ddsi_config.c @@ -778,7 +778,8 @@ static unsigned uint32_popcnt (uint32_t x) static void do_print_uint32_bitset (struct ddsi_cfgst *cfgst, uint32_t mask, size_t ncodes, const char **names, const uint32_t *codes, uint32_t sources, const char *suffix) { - char res[256] = "", *resp = res; + char res[256] = ""; + size_t res_offset = 0; const char *prefix = ""; #ifndef NDEBUG { @@ -809,17 +810,21 @@ static void do_print_uint32_bitset (struct ddsi_cfgst *cfgst, uint32_t mask, siz } if (pc_best != 0) { - resp += snprintf (resp, 256, "%s%s", prefix, names[i_best]); + int characters_written = snprintf (res + res_offset, sizeof(res) - res_offset, "%s%s", prefix, names[i_best]); + assert(characters_written >= 0); + res_offset += (size_t) characters_written; mask &= ~codes[i_best]; prefix = ","; } else { - resp += snprintf (resp, 256, "%s0x%x", prefix, (unsigned) mask); + int characters_written = snprintf (res + res_offset, sizeof(res) - res_offset, "%s0x%x", prefix, (unsigned) mask); + assert(characters_written >= 0); + res_offset += (size_t) characters_written; mask = 0; } } - assert (resp <= res + sizeof (res)); + assert (res_offset <= sizeof (res)); cfg_logelem (cfgst, sources, "%s%s", res, suffix); }