From 64d76198eaea1ef7e979eec1625ce8b369e9072c Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Wed, 16 Jul 2014 06:05:01 -0700 Subject: [PATCH] client: keep array subscripts in bounds. --- client/gpu_detect.cpp | 9 +++++---- client/gpu_detect.h | 13 ++++++++++++- client/gpu_opencl.cpp | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/client/gpu_detect.cpp b/client/gpu_detect.cpp index bdb43a52ca..20aee1df9f 100644 --- a/client/gpu_detect.cpp +++ b/client/gpu_detect.cpp @@ -37,6 +37,7 @@ #endif #include "coproc.h" +#include "gpu_detect.h" #include "file_names.h" #include "util.h" #include "str_replace.h" @@ -60,7 +61,7 @@ vector intel_gpus; vector ati_opencls; vector nvidia_opencls; vector intel_gpu_opencls; -vector other_opencls[MAX_RSC]; +vector other_opencls[MAX_OTHER_OPENCLS]; vector cpu_opencls; // Number of OpenCL coproc vendors other than AMD, NVIDIA or Intel @@ -281,7 +282,7 @@ void COPROCS::correlate_gpus( ati_opencls.clear(); nvidia_opencls.clear(); intel_gpu_opencls.clear(); - for (j=0; j &warnings) { ati_opencls.clear(); nvidia_opencls.clear(); intel_gpu_opencls.clear(); - for (int j=0; j &warnings) { } } - if (vendor_index >= MAX_RSC) { + if (vendor_index >= MAX_OTHER_OPENCLS) { // Too many OpenCL device vendors found (should never happen here) continue; // Discard this coprocessor's info } diff --git a/client/gpu_detect.h b/client/gpu_detect.h index ff554d10b4..40c8abb48f 100644 --- a/client/gpu_detect.h +++ b/client/gpu_detect.h @@ -15,14 +15,25 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . +#ifndef _GPU_DETECT_H_ +#define _GPU_DETECT_H_ + +#include "coproc.h" + +using std::vector; + +// NOTE: coprocs[0] is reserved for CPU, leaving MAX_RSC-1 +#define MAX_OTHER_OPENCLS MAX_RSC-1 + extern vector ati_gpus; extern vector nvidia_gpus; extern vector intel_gpus; extern vector nvidia_opencls; extern vector ati_opencls; extern vector intel_gpu_opencls; -extern vector other_opencls[MAX_RSC]; +extern vector other_opencls[MAX_OTHER_OPENCLS]; extern vector cpu_opencls; extern int num_other_opencl_types; +#endif diff --git a/client/gpu_opencl.cpp b/client/gpu_opencl.cpp index f660d9199a..83f5cd3f4c 100644 --- a/client/gpu_opencl.cpp +++ b/client/gpu_opencl.cpp @@ -537,7 +537,7 @@ void COPROCS::get_opencl( } } - if (vendor_index >= MAX_RSC) { + if (vendor_index >= MAX_OTHER_OPENCLS) { warnings.push_back("Too many OpenCL device vendors found"); continue; // Discard this coprocessor's info }