Browse Source

Add runtime bounds checks to bssl::Span.

Better safe than sorry.

Change-Id: Ia99fa59ef1345835e01c330d99707bc8899a33a1
Reviewed-on: https://boringssl-review.googlesource.com/27484
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
kris/onging/CECPQ3_patch15
David Benjamin 6 years ago
committed by CQ bot account: commit-bot@chromium.org
parent
commit
68478b7e9b
1 changed files with 13 additions and 5 deletions
  1. +13
    -5
      include/openssl/span.h

+ 13
- 5
include/openssl/span.h View File

@@ -22,7 +22,6 @@
extern "C++" {

#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <type_traits>

@@ -136,16 +135,25 @@ class Span : private internal::SpanBase<const T> {
const T *cend() const { return end(); };

T &front() const {
assert(size_ != 0);
if (size_ == 0) {
abort();
}
return data_[0];
}
T &back() const {
assert(size_ != 0);
if (size_ == 0) {
abort();
}
return data_[size_ - 1];
}

T &operator[](size_t i) const { return data_[i]; }
T &at(size_t i) const { return data_[i]; }
T &operator[](size_t i) const {
if (i >= size_) {
abort();
}
return data_[i];
}
T &at(size_t i) const { return (*this)[i]; }

Span subspan(size_t pos = 0, size_t len = npos) const {
if (pos > size_) {


Loading…
Cancel
Save