diff mbox

[2/3] Fix -Wformat-security warnings with clang

Message ID alpine.BSF.2.00.1212090305120.64779@toaster.local (mailing list archive)
State Accepted
Delegated to: Alex Netes
Headers show

Commit Message

Garrett Cooper Dec. 9, 2012, 11:06 a.m. UTC
clang with -Wformat-security warnings is extremely paranoid when it come 
to calling printf-like functions like osm_log* with a variable content 
buffer of some kind. This commit explicitly uses the "%s" format string to 
make formatting the variable buffer safer.

Signed-off-by: Garrett Cooper <yanegomi@gmail.com>
---
  opensm/osm_helper.c | 96 ++++++++++++++++++++++++++---------------------------
  1 file changed, 48 insertions(+), 48 deletions(-)
diff mbox

Patch

diff --git a/opensm/osm_helper.c b/opensm/osm_helper.c
index e13b044..10b88d7 100644
--- a/opensm/osm_helper.c
+++ b/opensm/osm_helper.c
@@ -888,7 +888,7 @@  void osm_dump_port_info(IN osm_log_t * p_log, IN ib_net64_t node_guid,
  		osm_dump_port_info_to_buf(node_guid, port_guid,
  					  port_num, p_pi, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);

  		/*  show the capabilities mask */
  		if (p_pi->capability_mask) {
@@ -910,7 +910,7 @@  void osm_dump_port_info_v2(IN osm_log_t * p_log, IN ib_net64_t node_guid,
  		osm_dump_port_info_to_buf(node_guid, port_guid,
  					  port_num, p_pi, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);

  		/*  show the capabilities mask */
  		if (p_pi->capability_mask) {
@@ -955,7 +955,7 @@  void osm_dump_mlnx_ext_port_info(IN osm_log_t * p_log, IN ib_net64_t node_guid,
  		osm_dump_mlnx_ext_port_info_to_buf(node_guid, port_guid,
  						   port_num, p_pi, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -970,7 +970,7 @@  void osm_dump_mlnx_ext_port_info_v2(IN osm_log_t * p_log, IN ib_net64_t node_gui
  		osm_dump_mlnx_ext_port_info_to_buf(node_guid, port_guid,
  						   port_num, p_pi, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
          }
  }

@@ -1072,7 +1072,7 @@  void osm_dump_portinfo_record(IN osm_log_t * p_log,

  		osm_dump_portinfo_record_to_buf(p_pir, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);

  		/*  show the capabilities mask */
  		if (p_pi->capability_mask) {
@@ -1094,7 +1094,7 @@  void osm_dump_portinfo_record_v2(IN osm_log_t * p_log,

  		osm_dump_portinfo_record_to_buf(p_pir, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);

  		/*  show the capabilities mask */
  		if (p_pi->capability_mask) {
@@ -1146,7 +1146,7 @@  void osm_dump_guid_info(IN osm_log_t * p_log, IN ib_net64_t node_guid,
  		osm_dump_guid_info_to_buf(node_guid, port_guid,
  					  block_num, p_gi, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1162,7 +1162,7 @@  void osm_dump_guid_info_v2(IN osm_log_t * p_log, IN ib_net64_t node_guid,
  		osm_dump_guid_info_to_buf(node_guid, port_guid,
  					  block_num, p_gi, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1207,7 +1207,7 @@  void osm_dump_guidinfo_record(IN osm_log_t * p_log,

  		osm_dump_guidinfo_record_to_buf(p_gir, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1221,7 +1221,7 @@  void osm_dump_guidinfo_record_v2(IN osm_log_t * p_log,

  		osm_dump_guidinfo_record_to_buf(p_gir, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1264,7 +1264,7 @@  void osm_dump_node_info(IN osm_log_t * p_log, IN const ib_node_info_t * p_ni,

  		osm_dump_node_info_to_buf(p_ni, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1276,7 +1276,7 @@  void osm_dump_node_info_v2(IN osm_log_t * p_log, IN const ib_node_info_t * p_ni,

  		osm_dump_node_info_to_buf(p_ni, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1333,7 +1333,7 @@  void osm_dump_node_record(IN osm_log_t * p_log,

  		osm_dump_node_record_to_buf(p_nr, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1347,7 +1347,7 @@  void osm_dump_node_record_v2(IN osm_log_t * p_log,

  		osm_dump_node_record_to_buf(p_nr, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1401,7 +1401,7 @@  void osm_dump_path_record(IN osm_log_t * p_log, IN const ib_path_rec_t * p_pr,

  		osm_dump_path_record_to_buf(p_pr, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1413,7 +1413,7 @@  void osm_dump_path_record_v2(IN osm_log_t * p_log, IN const ib_path_rec_t * p_pr

  		osm_dump_path_record_to_buf(p_pr, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1486,7 +1486,7 @@  void osm_dump_multipath_record(IN osm_log_t * p_log,

  		osm_dump_multipath_record_to_buf(p_mpr, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1500,7 +1500,7 @@  void osm_dump_multipath_record_v2(IN osm_log_t * p_log,

  		osm_dump_multipath_record_to_buf(p_mpr, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1547,7 +1547,7 @@  void osm_dump_mc_record(IN osm_log_t * p_log, IN const ib_member_rec_t * p_mcmr,

  		osm_dump_mc_record_to_buf(p_mcmr, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1559,7 +1559,7 @@  void osm_dump_mc_record_v2(IN osm_log_t * p_log, IN const ib_member_rec_t * p_mc

  		osm_dump_mc_record_to_buf(p_mcmr, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1664,7 +1664,7 @@  void osm_dump_service_record(IN osm_log_t * p_log,

  		osm_dump_service_record_to_buf(p_sr, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1678,7 +1678,7 @@  void osm_dump_service_record_v2(IN osm_log_t * p_log,

  		osm_dump_service_record_to_buf(p_sr, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1768,7 +1768,7 @@  void osm_dump_inform_info(IN osm_log_t * p_log,
  		else
  			osm_dump_inform_info_to_buf(p_ii, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1785,7 +1785,7 @@  void osm_dump_inform_info_v2(IN osm_log_t * p_log,
  		else
  			osm_dump_inform_info_to_buf(p_ii, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1897,7 +1897,7 @@  void osm_dump_inform_info_record(IN osm_log_t * p_log,
  		else
  			osm_dump_inform_info_record_to_buf(p_iir, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1914,7 +1914,7 @@  void osm_dump_inform_info_record_v2(IN osm_log_t * p_log,
  		else
  			osm_dump_inform_info_record_to_buf(p_iir, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -1945,7 +1945,7 @@  void osm_dump_link_record(IN osm_log_t * p_log,

  		osm_dump_link_record_to_buf(p_lr, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -1959,7 +1959,7 @@  void osm_dump_link_record_v2(IN osm_log_t * p_log,

  		osm_dump_link_record_to_buf(p_lr, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -2002,7 +2002,7 @@  void osm_dump_switch_info(IN osm_log_t * p_log,

  		osm_dump_switch_info_to_buf(p_si, buf);

-		osm_log(p_log, OSM_LOG_VERBOSE, buf);
+		osm_log(p_log, OSM_LOG_VERBOSE, "%s", buf);
  	}
  }

@@ -2016,7 +2016,7 @@  void osm_dump_switch_info_v2(IN osm_log_t * p_log,

  		osm_dump_switch_info_to_buf(p_si, buf);

-		osm_log_v2(p_log, OSM_LOG_VERBOSE, file_id, buf);
+		osm_log_v2(p_log, OSM_LOG_VERBOSE, file_id, "%s", buf);
  	}
  }

@@ -2066,7 +2066,7 @@  void osm_dump_switch_info_record(IN osm_log_t * p_log,

  		osm_dump_switch_info_record_to_buf(p_sir, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -2080,7 +2080,7 @@  void osm_dump_switch_info_record_v2(IN osm_log_t * p_log,

  		osm_dump_switch_info_record_to_buf(p_sir, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -2120,7 +2120,7 @@  void osm_dump_pkey_block(IN osm_log_t * p_log, IN uint64_t port_guid,
  		osm_dump_pkey_block_to_buf(port_guid, block_num, port_num,
  					   p_pkey_tbl, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -2136,7 +2136,7 @@  void osm_dump_pkey_block_v2(IN osm_log_t * p_log, IN uint64_t port_guid,
  		osm_dump_pkey_block_to_buf(port_guid, block_num,
  					   port_num, p_pkey_tbl, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -2179,7 +2179,7 @@  void osm_dump_slvl_map_table(IN osm_log_t * p_log, IN uint64_t port_guid,
  		osm_dump_slvl_map_table_to_buf(port_guid, in_port_num,
  					       out_port_num, p_slvl_tbl, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -2195,7 +2195,7 @@  void osm_dump_slvl_map_table_v2(IN osm_log_t * p_log, IN uint64_t port_guid,
  		osm_dump_slvl_map_table_to_buf(port_guid, in_port_num,
  					       out_port_num, p_slvl_tbl, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -2237,7 +2237,7 @@  void osm_dump_vl_arb_table(IN osm_log_t * p_log, IN uint64_t port_guid,
  		osm_dump_vl_arb_table_to_buf(port_guid, block_num,
  					     port_num, p_vla_tbl, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -2253,7 +2253,7 @@  void osm_dump_vl_arb_table_v2(IN osm_log_t * p_log, IN uint64_t port_guid,
  		osm_dump_vl_arb_table_to_buf(port_guid, block_num,
  					     port_num, p_vla_tbl, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -2285,7 +2285,7 @@  void osm_dump_sm_info(IN osm_log_t * p_log, IN const ib_sm_info_t * p_smi,

  		osm_dump_sm_info_to_buf(p_smi, buf);

-		osm_log(p_log, OSM_LOG_DEBUG, buf);
+		osm_log(p_log, OSM_LOG_DEBUG, "%s", buf);
  	}
  }

@@ -2297,7 +2297,7 @@  void osm_dump_sm_info_v2(IN osm_log_t * p_log, IN const ib_sm_info_t * p_smi,

  		osm_dump_sm_info_to_buf(p_smi, buf);

-		osm_log_v2(p_log, OSM_LOG_DEBUG, file_id, buf);
+		osm_log_v2(p_log, OSM_LOG_DEBUG, file_id, "%s", buf);
  	}
  }

@@ -2336,7 +2336,7 @@  void osm_dump_sm_info_record(IN osm_log_t * p_log,

  		osm_dump_sm_info_record_to_buf(p_smir, buf);

-		osm_log(p_log, OSM_LOG_DEBUG, buf);
+		osm_log(p_log, OSM_LOG_DEBUG, "%s", buf);
  	}
  }

@@ -2350,7 +2350,7 @@  void osm_dump_sm_info_record_v2(IN osm_log_t * p_log,

  		osm_dump_sm_info_record_to_buf(p_smir, buf);

-		osm_log_v2(p_log, OSM_LOG_DEBUG, file_id, buf);
+		osm_log_v2(p_log, OSM_LOG_DEBUG, file_id, "%s", buf);
  	}
  }

@@ -2569,7 +2569,7 @@  void osm_dump_notice(IN osm_log_t * p_log,
  		else
  			osm_dump_notice_to_buf(p_ntci, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -2585,7 +2585,7 @@  void osm_dump_notice_v2(IN osm_log_t * p_log,
  		else
  			osm_dump_notice_to_buf(p_ntci, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -2700,7 +2700,7 @@  void osm_dump_dr_smp(IN osm_log_t * p_log, IN const ib_smp_t * p_smp,

  		osm_dump_dr_smp_to_buf(p_smp, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s", buf);
  	}
  }

@@ -2712,7 +2712,7 @@  void osm_dump_dr_smp_v2(IN osm_log_t * p_log, IN const ib_smp_t * p_smp,

  		osm_dump_dr_smp_to_buf(p_smp, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }

@@ -2774,7 +2774,7 @@  void osm_dump_sa_mad(IN osm_log_t * p_log, IN const ib_sa_mad_t * p_mad,

  		osm_dump_sa_mad_to_buf(p_mad, buf);

-		osm_log(p_log, log_level, buf);
+		osm_log(p_log, log_level, "%s\n", buf);
  	}
  }

@@ -2786,7 +2786,7 @@  void osm_dump_sa_mad_v2(IN osm_log_t * p_log, IN const ib_sa_mad_t * p_mad,

  		osm_dump_sa_mad_to_buf(p_mad, buf);

-		osm_log_v2(p_log, log_level, file_id, buf);
+		osm_log_v2(p_log, log_level, file_id, "%s", buf);
  	}
  }