From patchwork Sun Dec 4 12:19:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFya28gTcOka2Vsw6Q=?= X-Patchwork-Id: 87996 Received: from [127.0.0.1] by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1p1nxs-00ATSH-1Y; Sun, 04 Dec 2022 12:19:24 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by www.linuxtv.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p1nxn-00ATRu-Va for vdr@linuxtv.org; Sun, 04 Dec 2022 12:19:22 +0000 Received: from jyty (dsl-hkibng31-54fae6-199.dhcp.inet.fi [84.250.230.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: msmakela) by meesny.iki.fi (Postfix) with ESMTPSA id AA23C2006A for ; Sun, 4 Dec 2022 14:19:17 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1670156357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=/JzpRezAaz1tvbSKBmb9uH7kkhqhKXvvBlPICypMQcE=; b=rzgVg3rroYXPt+IHy0IVb6c3XtFaglnHm9/wDgSowa1+lJA1h5VFsOwUbX3QMUipWMGTUS f6vJ6kEJFGMUGUJIvvf4qwuAYz3pvteRTh3Y3Z+z9P4E3gI+m4qMODrn6N+xVS1N0YuzX5 Ocm2CEgS0oSPegERTY9+hrnXlSJYyc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1670156357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=/JzpRezAaz1tvbSKBmb9uH7kkhqhKXvvBlPICypMQcE=; b=NsWaQVwQ3/SiHTa2uI95HqubbTjSVfXIEBEGpqa5pi4kdmxvYYv4DiCKqFZ/sePf/0Gsu+ xoMieEbK3qNo8zGxBJ6oB7uZ2uT/gfTrdpZf7ukN7g3nB+mx4mT/XD1R/Zuj7ixEYO1P/5 v8Y8gh7mIGKbk9s2ePXK60Q+0a04X5I= ARC-Seal: i=1; s=meesny; d=iki.fi; t=1670156357; a=rsa-sha256; cv=none; b=kjScQnd9rucv0xeyP6YQM2h/DPd2Scht4+ylk8ySWo6zh+BFyqMG4Mz+1Ea4R+LvPiIkfB VzV0Ny+NaIH0DHj4nQynZLK9PvmDVOQUhTOWaIfI6JIcaZpE6EDE09AncCyU4AlhP755tZ 7iK5o1dlp+5eqvbWARt3JJZUHQv4GCM= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=msmakela smtp.mailfrom=marko.makela@iki.fi Date: Sun, 4 Dec 2022 14:19:16 +0200 From: Marko =?iso-8859-1?q?M=E4kel=E4?= To: VDR Mailing List Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-LSpam-Score: -1.1 (-) X-LSpam-Report: No, score=-1.1 required=5.0 tests=BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_EXCESS_BASE64=0.979 autolearn=ham autolearn_force=no Subject: [vdr] [PATCH] Fix undefined behaviour X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: VDR Mailing List Errors-To: vdr-bounces@linuxtv.org Sender: "vdr" Another day, another sanitizer. After fixing issues reported by -fsanitize=address yesterday, I gave -fsanitize=undefined a try. The GCC documentation points to the clang documentation: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html The issues related to cControl::player were tricky. In the end, I figured it out after setting UBSAN_OPTIONS=print_stacktrace=1 and setting a breakpoint on _Unwind_Backtrace(). The name of the reporting function in my system was __ubsan_handle_dynamic_type_cache_miss(), nothing about "vptr". Also, the diagnostics was misleadingly pointing to the body of the constructor, and not the initializer list where a data member was being assigned to before the base class had been initialized. The -fsanitize=undefined in clang might report more things. Next I may give -fsanitize=thread a try. GCC does not implement -fsanitize=memory (checking for the use of uninitialized memory) at all. It will require clang and libc++ (not libstdc++) and that all libraries except libc are built with -fsanitize=memory. If you are familiar with Valgrind's default memcheck tool, it is roughly comparable to the combination of -fsanitize=address and -fsanitize=memory. Marko From b69ff7105d4bb8d933f0214f34b103fda8e8b155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Sun, 4 Dec 2022 13:42:57 +0200 Subject: [PATCH] Fix GCC 8.3.0 -fsanitize=undefined sections.c:183:30: runtime error: variable length array bound evaluates to non-positive value 0 device.c:251:31: runtime error: variable length array bound evaluates to non-positive value 0 osd.h:301:37: runtime error: signed integer overflow: -2147483648 - 2147483647 cannot be represented in type 'int' osd.h:301:37: runtime error: signed integer overflow: -2147483647 - 2147483647 cannot be represented in type 'int' transfer.c:71:11: runtime error: member access within address 0x020f0428 which does not point to an object of type 'cTransferControl' dvbplayer.c:984:11: runtime error: member access within address 0x02a388d0 which does not point to an object of type 'cDvbPlayerControl' --- device.c | 2 +- dvbplayer.c | 3 ++- font.c | 3 ++- osd.h | 4 ++-- sections.c | 2 +- transfer.c | 3 ++- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/device.c b/device.c index 4e987389..a770aa90 100644 --- a/device.c +++ b/device.c @@ -248,7 +248,7 @@ cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool LiveView { // Collect the current priorities of all CAM slots that can decrypt the channel: int NumCamSlots = CamSlots.Count(); - int SlotPriority[NumCamSlots]; + int SlotPriority[std::max(NumCamSlots, 1)]; int NumUsableSlots = 0; bool InternalCamNeeded = false; if (Channel->Ca() >= CA_ENCRYPTED_MIN) { diff --git a/dvbplayer.c b/dvbplayer.c index 2ee846b6..72bc46ad 100644 --- a/dvbplayer.c +++ b/dvbplayer.c @@ -981,8 +981,9 @@ bool cDvbPlayer::GetReplayMode(bool &Play, bool &Forward, int &Speed) // --- cDvbPlayerControl ----------------------------------------------------- cDvbPlayerControl::cDvbPlayerControl(const char *FileName, bool PauseLive) -:cControl(player = new cDvbPlayer(FileName, PauseLive)) +:cControl(new cDvbPlayer(FileName, PauseLive)) { + player = static_cast(cControl::player); } cDvbPlayerControl::~cDvbPlayerControl() diff --git a/font.c b/font.c index 8b37798c..c78b1a15 100644 --- a/font.c +++ b/font.c @@ -74,7 +74,8 @@ cGlyph::cGlyph(uint CharCode, FT_GlyphSlotRec_ *GlyphData) rows = GlyphData->bitmap.rows; pitch = GlyphData->bitmap.pitch; bitmap = MALLOC(uchar, rows * pitch); - memcpy(bitmap, GlyphData->bitmap.buffer, rows * pitch); + if (int bytes = rows * pitch) + memcpy(bitmap, GlyphData->bitmap.buffer, bytes); } cGlyph::~cGlyph() diff --git a/osd.h b/osd.h index 77722662..7a293321 100644 --- a/osd.h +++ b/osd.h @@ -298,8 +298,8 @@ public: struct tArea { int x1, y1, x2, y2; int bpp; - int Width(void) const { return x2 - x1 + 1; } - int Height(void) const { return y2 - y1 + 1; } + int Width(void) const { return x2 < 0 ? 0 : x2 - x1 + 1; } + int Height(void) const { return y2 < 0 ? 0 : y2 - y1 + 1; } bool Intersects(const tArea &Area) const { return !(x2 < Area.x1 || x1 > Area.x2 || y2 < Area.y1 || y1 > Area.y2); } }; diff --git a/sections.c b/sections.c index 51a2823c..4d90b19c 100644 --- a/sections.c +++ b/sections.c @@ -180,7 +180,7 @@ void cSectionHandler::Action(void) startFilters = false; } int NumFilters = filterHandles.Count(); - pollfd pfd[NumFilters]; + pollfd pfd[std::max(NumFilters, 1)]; for (cFilterHandle *fh = filterHandles.First(); fh; fh = filterHandles.Next(fh)) { int i = fh->Index(); pfd[i].fd = fh->handle; diff --git a/transfer.c b/transfer.c index 88931e58..b888910a 100644 --- a/transfer.c +++ b/transfer.c @@ -68,8 +68,9 @@ void cTransfer::Receive(const uchar *Data, int Length) cDevice *cTransferControl::receiverDevice = NULL; cTransferControl::cTransferControl(cDevice *ReceiverDevice, const cChannel *Channel) -:cControl(transfer = new cTransfer(Channel), true) +:cControl(new cTransfer(Channel), true) { + transfer = static_cast(player); ReceiverDevice->AttachReceiver(transfer); receiverDevice = ReceiverDevice; } -- 2.38.1