[v2] lib/bitratestats: add NULL sanity checks

Message ID 20180712104948.3113-1-remy.horton@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] lib/bitratestats: add NULL sanity checks |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Remy Horton July 12, 2018, 10:49 a.m. UTC
  If rte_stats_bitrate_reg() or rte_stats_bitrate_calc() are
passed NULL as the parameter for the stats structure, the
result is a crash. Fixed by adding a sanity check that makes
sure the passed-in pointer is not NULL.

Fixes: 2ad7ba9a6567 ("bitrate: add bitrate statistics library")

Signed-off-by: Remy Horton <remy.horton@intel.com>
---
 lib/librte_bitratestats/rte_bitrate.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Ferruh Yigit July 20, 2018, 3:31 p.m. UTC | #1
On 7/12/2018 11:49 AM, Remy Horton wrote:
> If rte_stats_bitrate_reg() or rte_stats_bitrate_calc() are
> passed NULL as the parameter for the stats structure, the
> result is a crash. Fixed by adding a sanity check that makes
> sure the passed-in pointer is not NULL.
> 
> Fixes: 2ad7ba9a6567 ("bitrate: add bitrate statistics library")
> 
> Signed-off-by: Remy Horton <remy.horton@intel.com>

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
  
Thomas Monjalon July 26, 2018, 6:07 p.m. UTC | #2
20/07/2018 17:31, Ferruh Yigit:
> On 7/12/2018 11:49 AM, Remy Horton wrote:
> > If rte_stats_bitrate_reg() or rte_stats_bitrate_calc() are
> > passed NULL as the parameter for the stats structure, the
> > result is a crash. Fixed by adding a sanity check that makes
> > sure the passed-in pointer is not NULL.
> > 
> > Fixes: 2ad7ba9a6567 ("bitrate: add bitrate statistics library")
> > 
> > Signed-off-by: Remy Horton <remy.horton@intel.com>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_bitratestats/rte_bitrate.c b/lib/librte_bitratestats/rte_bitrate.c
index 964e3c3..c4b28f6 100644
--- a/lib/librte_bitratestats/rte_bitrate.c
+++ b/lib/librte_bitratestats/rte_bitrate.c
@@ -47,6 +47,9 @@  rte_stats_bitrate_reg(struct rte_stats_bitrates *bitrate_data)
 	};
 	int return_value;
 
+	if (bitrate_data == NULL)
+		return -EINVAL;
+
 	return_value = rte_metrics_reg_names(&names[0], ARRAY_SIZE(names));
 	if (return_value >= 0)
 		bitrate_data->id_stats_set = return_value;
@@ -65,6 +68,9 @@  rte_stats_bitrate_calc(struct rte_stats_bitrates *bitrate_data,
 	const int64_t alpha_percent = 20;
 	uint64_t values[6];
 
+	if (bitrate_data == NULL)
+		return -EINVAL;
+
 	ret_code = rte_eth_stats_get(port_id, &eth_stats);
 	if (ret_code != 0)
 		return ret_code;