[ofa-general] Re: [PATCHv2] osm: source and destination strings overlap when using sprintf()
Hal Rosenstock
halr at voltaire.com
Wed Apr 25 05:57:33 PDT 2007
Hi Yevgeny,
On Wed, 2007-04-25 at 08:10, Yevgeny Kliteynik wrote:
> Hi Hal,
>
> [V2] - Fixing a problematic usage of sprintf() in osm_helper.c:
>
> When using sprintf(), source and destination strings should
> not overlap, otherwise the function behavior is undefined.
> Please apply to ofed_1_2 and to master.
Is this a test case or does this currently occur with some OFED 1.2 code
? Just wondering...
-- Hal
> Thanks.
>
> -- Yevgeny
>
> Signed-off-by: Yevgeny Kliteynik <kliteyn at dev.mellanox.co.il>
> ---
> osm/opensm/osm_helper.c | 26 +++++++++++++-------------
> 1 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/osm/opensm/osm_helper.c b/osm/opensm/osm_helper.c
> index 14474e7..483b73b 100644
> --- a/osm/opensm/osm_helper.c
> +++ b/osm/opensm/osm_helper.c
> @@ -1157,9 +1157,9 @@ osm_dump_multipath_record(
> {
> for (i = 0; i < p_mpr->sgid_count; i++)
> {
> - sprintf( buf_line, "%s\t\t\t\tsgid%02d.................."
> + sprintf( buf_line + strlen(buf_line), "\t\t\t\tsgid%02d.................."
> "0x%016" PRIx64 " : 0x%016" PRIx64 "\n",
> - buf_line, i + 1, cl_ntoh64( p_gid->unicast.prefix ),
> + i + 1, cl_ntoh64( p_gid->unicast.prefix ),
> cl_ntoh64( p_gid->unicast.interface_id ) );
> p_gid++;
> }
> @@ -1168,9 +1168,9 @@ osm_dump_multipath_record(
> {
> for (i = 0; i < p_mpr->dgid_count; i++)
> {
> - sprintf( buf_line, "%s\t\t\t\tdgid%02d.................."
> + sprintf( buf_line + strlen(buf_line), "\t\t\t\tdgid%02d.................."
> "0x%016" PRIx64 " : 0x%016" PRIx64 "\n",
> - buf_line, i + 1, cl_ntoh64( p_gid->unicast.prefix ),
> + i + 1, cl_ntoh64( p_gid->unicast.prefix ),
> cl_ntoh64( p_gid->unicast.interface_id ) );
> p_gid++;
> }
> @@ -1657,8 +1657,8 @@ osm_dump_pkey_block(
> {
> buf_line[0] = '\0';
> for (i = 0; i < 32; i++)
> - sprintf( buf_line,"%s 0x%04x |",
> - buf_line, cl_ntoh16(p_pkey_tbl->pkey_entry[i]));
> + sprintf( buf_line + strlen(buf_line)," 0x%04x |",
> + cl_ntoh16(p_pkey_tbl->pkey_entry[i]));
>
> osm_log( p_log, log_level,
> "P_Key table dump:\n"
> @@ -1693,10 +1693,10 @@ osm_dump_slvl_map_table(
> buf_line1[0] = '\0';
> buf_line2[0] = '\0';
> for (i = 0; i < 16; i++)
> - sprintf( buf_line1,"%s %-2u |", buf_line1, i);
> + sprintf( buf_line1 + strlen(buf_line1)," %-2u |", i);
> for (i = 0; i < 16; i++)
> - sprintf( buf_line2,"%s0x%01X |",
> - buf_line2, ib_slvl_table_get(p_slvl_tbl, i));
> + sprintf( buf_line2 + strlen(buf_line2),"0x%01X |",
> + ib_slvl_table_get(p_slvl_tbl, i));
> osm_log( p_log, log_level,
> "SLtoVL dump:\n"
> "\t\t\tport_guid............0x%016" PRIx64 "\n"
> @@ -1730,11 +1730,11 @@ osm_dump_vl_arb_table(
> buf_line1[0] = '\0';
> buf_line2[0] = '\0';
> for (i = 0; i < 32; i++)
> - sprintf( buf_line1,"%s 0x%01X |",
> - buf_line1, p_vla_tbl->vl_entry[i].vl);
> + sprintf( buf_line1 + strlen(buf_line1)," 0x%01X |",
> + p_vla_tbl->vl_entry[i].vl);
> for (i = 0; i < 32; i++)
> - sprintf( buf_line2,"%s 0x%01X |",
> - buf_line2, p_vla_tbl->vl_entry[i].weight);
> + sprintf( buf_line2 + strlen(buf_line2)," 0x%01X |",
> + p_vla_tbl->vl_entry[i].weight);
> osm_log( p_log, log_level,
> "VlArb dump:\n"
> "\t\t\tport_guid...........0x%016" PRIx64 "\n"
More information about the general
mailing list