summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2019-11-18 12:07:11 +0200
committerTomi Valkeinen <tomi.valkeinen@ti.com>2019-11-18 12:12:39 +0200
commit7a52c7d720398da7df242aeef7be652b54290e94 (patch)
tree4d3b3b6de8358ec3b19a4c7959ecbf9cea67b755
parentd6dc724f16672cbb3eed382815514f4c9a0246d4 (diff)
fbs: check params and ensure drmModeAddFB2 is passed correctly sized arrays
Check that parameter vectors are of the same size, and match the number of planes. Extend the vectors to 4, as drmModeAddFB2() expects to get arrays of 4 elements. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com> Reported-by: Matt Hoosier <matt.hoosier@garmin.com>
-rw-r--r--kms++/src/dmabufframebuffer.cpp5
-rw-r--r--kms++/src/extframebuffer.cpp6
2 files changed, 11 insertions, 0 deletions
diff --git a/kms++/src/dmabufframebuffer.cpp b/kms++/src/dmabufframebuffer.cpp
index 00ab94e..feac116 100644
--- a/kms++/src/dmabufframebuffer.cpp
+++ b/kms++/src/dmabufframebuffer.cpp
@@ -28,6 +28,9 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height
m_num_planes = format_info.num_planes;
+ if (fds.size() != m_num_planes || pitches.size() != m_num_planes || offsets.size() != m_num_planes)
+ throw std::invalid_argument("the size of fds, pitches and offsets has to match number of planes");
+
for (int i = 0; i < format_info.num_planes; ++i) {
FramebufferPlane& plane = m_planes[i];
@@ -45,6 +48,8 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height
uint32_t id;
uint32_t bo_handles[4] = { m_planes[0].handle, m_planes[1].handle, m_planes[2].handle, m_planes[3].handle };
+ pitches.resize(4);
+ offsets.resize(4);
r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format,
bo_handles, pitches.data(), offsets.data(), &id, 0);
if (r)
diff --git a/kms++/src/extframebuffer.cpp b/kms++/src/extframebuffer.cpp
index 28cc138..9f7ab6c 100644
--- a/kms++/src/extframebuffer.cpp
+++ b/kms++/src/extframebuffer.cpp
@@ -24,6 +24,9 @@ ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, Pixe
m_num_planes = format_info.num_planes;
+ if (handles.size() != m_num_planes || pitches.size() != m_num_planes || offsets.size() != m_num_planes)
+ throw std::invalid_argument("the size of handles, pitches and offsets has to match number of planes");
+
for (int i = 0; i < format_info.num_planes; ++i) {
FramebufferPlane& plane = m_planes[i];
@@ -36,6 +39,9 @@ ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, Pixe
}
uint32_t id;
+ handles.resize(4);
+ pitches.resize(4);
+ offsets.resize(4);
int r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format, handles.data(), pitches.data(), offsets.data(), &id, 0);
if (r)
throw std::invalid_argument(string("Failed to create ExtFramebuffer: ") + strerror(r));