Blob Blame History Raw
From eb259fb96143dccf42f41523093987eb1fcdb739 Mon Sep 17 00:00:00 2001
From: kamel5 <vdr.kamel5 (at) gmx (dot) net>
Date: Thu, 7 Apr 2022 13:31:15 +0200
Subject: Fixed possible segfault when showing scrollbar in search result lists

A segfault is possible if numSteps is greater than height in
"cRecMenu::createScrollbar()".

diff --git a/recmenu.c b/recmenu.c
index 32650c1..3f2916f 100644
--- a/recmenu.c
+++ b/recmenu.c
@@ -123,8 +123,7 @@ void cRecMenu::InitMenu(bool complete) {
         width -= scrollbarWidth + border;
         osdManager.releasePixmap(pixmapScrollBar);
         pixmapScrollBar = NULL;
-        delete imgScrollBar;
-        imgScrollBar = NULL;
+        DELETENULL(imgScrollBar);
     }
     osdManager.releasePixmap(pixmap);
     pixmap = NULL;
@@ -592,14 +591,14 @@ void cRecMenu::DrawScrollBar(void) {
     if (!pixmapScrollBar)
        return;
     pixmapScrollBar->Fill(theme.Color(clrBorder));
-    pixmapScrollBar->DrawRectangle(cRect(2,2,pixmapScrollBar->ViewPort().Width()-4, pixmapScrollBar->ViewPort().Height() - 4), theme.Color(clrBackground));
+    pixmapScrollBar->DrawRectangle(cRect(2, 2, pixmapScrollBar->ViewPort().Width() - 4, pixmapScrollBar->ViewPort().Height() - 4), theme.Color(clrBackground));
     
     int totalNumItems = GetTotalNumMenuItems();
     if (!totalNumItems)
        return;
-    if (imgScrollBar == NULL) {
+    if (!imgScrollBar) {
         int scrollBarImgHeight = (pixmapScrollBar->ViewPort().Height() - 8) * numItems / totalNumItems;
-        imgScrollBar = createScrollbar(pixmapScrollBar->ViewPort().Width()-8, scrollBarImgHeight, theme.Color(clrHighlight), theme.Color(clrHighlightBlending));
+        imgScrollBar = createScrollbar(pixmapScrollBar->ViewPort().Width() - 8, scrollBarImgHeight, theme.Color(clrHighlight), theme.Color(clrHighlightBlending));
     }
     int offset = (pixmapScrollBar->ViewPort().Height() - 8) * startIndex / totalNumItems;
     pixmapScrollBar->DrawImage(cPoint(4, 2 + offset), *imgScrollBar);
@@ -678,25 +677,21 @@ eRecMenuState cRecMenu::ProcessKey(eKeys Key) {
 cImage *cRecMenu::createScrollbar(int width, int height, tColor clrBgr, tColor clrBlend) {
     cImage *image = new cImage(cSize(width, height));
     image->Fill(clrBgr);
-    if (config.style != eStyleFlat) {
+    if (height >= 32 && config.style != eStyleFlat) {
         int numSteps = 64;
         int alphaStep = 0x03;
-        if (height < 30)
-            return image;
-        else if (height < 100) {
+        if (height < 100) {
             numSteps = 32;
             alphaStep = 0x06;
         }
-        int stepY = 0.5*height / numSteps;
-        if (stepY == 0)
-            stepY = 1;
+        int stepY = std::max(1, (int)(0.5 * height / numSteps));
         int alpha = 0x40;
         tColor clr;
-        for (int i = 0; i<numSteps; i++) {
+        for (int i = 0; i < numSteps; i++) {
             clr = AlphaBlend(clrBgr, clrBlend, alpha);
-            for (int y = i*stepY; y < (i+1)*stepY; y++) {
-                for (int x=0; x<width; x++) {
-                    image->SetPixel(cPoint(x,y), clr);
+            for (int y = i * stepY; y < (i + 1) * stepY; y++) {
+                for (int x = 0; x < width; x++) {
+                    image->SetPixel(cPoint(x, y), clr);
                 }
             }
             alpha += alphaStep;
-- 
cgit v0.10.2