This is an automated email from the ASF dual-hosted git repository. bcall pushed a commit to branch 7.0.x in repository https://git-dual.apache.org/repos/asf/trafficserver.git
commit 407b5451608eabbdedca41355b6df046713fc23a Author: James Peach <jpe...@apache.org> AuthorDate: Thu Sep 15 09:46:14 2016 -0700 TS-4871: Check for TSStatCreate failure. (cherry picked from commit 0bd6d8f47a473188a1ffc872b51d8567004ca207) --- example/statistic/statistic.cc | 1 + proxy/InkAPI.cc | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/example/statistic/statistic.cc b/example/statistic/statistic.cc index f39c21c..5b10125 100644 --- a/example/statistic/statistic.cc +++ b/example/statistic/statistic.cc @@ -49,6 +49,7 @@ TSPluginInit(int /* argc */, const char * /* argv */ []) id = TSStatCreate(name, TS_RECORDDATATYPE_INT, TS_STAT_NON_PERSISTENT, TS_STAT_SYNC_SUM); if (id == TS_ERROR) { TSError("%s: failed to register '%s'", PLUGIN_NAME, name); + return; } } diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc index 04d19d7..0abcce7 100644 --- a/proxy/InkAPI.cc +++ b/proxy/InkAPI.cc @@ -670,6 +670,17 @@ sdk_sanity_check_mutex(Ptr<ProxyMutex> &m) return m ? TS_SUCCESS : TS_ERROR; } +// Plugin metric IDs index the plugin RSB, so bounds check against that. +static TSReturnCode +sdk_sanity_check_stat_id(int id) +{ + if (id < 0 || id >= api_rsb->max_stats) { + return TS_ERROR; + } + + return TS_SUCCESS; +} + /** The function checks if the buffer is Modifiable and returns true if it is modifiable, else returns false. @@ -6919,30 +6930,33 @@ TSStatCreate(const char *the_name, TSRecordDataType the_type, TSStatPersistence } void -TSStatIntIncrement(int the_stat, TSMgmtInt amount) +TSStatIntIncrement(int id, TSMgmtInt amount) { - RecIncrRawStat(api_rsb, NULL, the_stat, amount); + sdk_assert(sdk_sanity_check_stat_id(id)); + RecIncrRawStat(api_rsb, NULL, id, amount); } void -TSStatIntDecrement(int the_stat, TSMgmtInt amount) +TSStatIntDecrement(int id, TSMgmtInt amount) { - RecDecrRawStat(api_rsb, NULL, the_stat, amount); + RecDecrRawStat(api_rsb, NULL, id, amount); } TSMgmtInt -TSStatIntGet(int the_stat) +TSStatIntGet(int id) { TSMgmtInt value; - RecGetGlobalRawStatSum(api_rsb, the_stat, &value); + sdk_assert(sdk_sanity_check_stat_id(id)); + RecGetGlobalRawStatSum(api_rsb, id, &value); return value; } void -TSStatIntSet(int the_stat, TSMgmtInt value) +TSStatIntSet(int id, TSMgmtInt value) { - RecSetGlobalRawStatSum(api_rsb, the_stat, value); + sdk_assert(sdk_sanity_check_stat_id(id)); + RecSetGlobalRawStatSum(api_rsb, id, value); } TSReturnCode -- To stop receiving notification emails like this one, please contact "commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.