Skip to content

Commit

Permalink
Resolve snprintf buffer overflow under GCC 12.3.0 (#1817)
Browse files Browse the repository at this point in the history
* ddsi_config: Fix buffer overflow for snprintf under GCC 12.3.0

* ddsi_config: Update generated files
  • Loading branch information
noxpardalis authored Aug 30, 2023
1 parent 7df82fb commit 7c5e790
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/manual/config/config_file_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,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] -->
Expand Down
2 changes: 1 addition & 1 deletion etc/cyclonedds.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==<br>
# 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]
Expand Down
2 changes: 1 addition & 1 deletion etc/cyclonedds.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==&lt;br&gt;
<!--- 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] -->
Expand Down
2 changes: 1 addition & 1 deletion src/core/ddsi/defconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] */
Expand Down
13 changes: 9 additions & 4 deletions src/core/ddsi/src/ddsi_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 7c5e790

Please sign in to comment.