-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0001-Protect-against-negative-bitshift.patch
40 lines (35 loc) · 1.32 KB
/
0001-Protect-against-negative-bitshift.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From e1e473650b45aff0b6a1fc50f4bdd7752dc45c85 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <[email protected]>
Date: Tue, 1 Mar 2022 16:37:22 -0500
Subject: [PATCH 1/4] Protect against negative bitshift
Coverity scan identified that SSCG_FILE_TYPE_UNKNOWN could cause the
bitshifts further down to attempt to shift a negative number, which
results in undefined behavior. Though it should never occur that this
function is called with an invalid type, it's best to be overly
cautious and check for it.
Signed-off-by: Stephen Gallagher <[email protected]>
---
src/io_utils.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/io_utils.c b/src/io_utils.c
index 1b8bc41..0e05ed9 100644
--- a/src/io_utils.c
+++ b/src/io_utils.c
@@ -99,10 +99,16 @@ struct sscg_stream *
sscg_io_utils_get_stream_by_type (struct sscg_stream **streams,
enum sscg_file_type filetype)
{
struct sscg_stream *stream = NULL;
+ if (filetype < 0 || filetype > SSCG_NUM_FILE_TYPES)
+ {
+ SSCG_LOG (SSCG_DEFAULT, "Unknown filetype for stream");
+ return NULL;
+ }
+
/* First see if this path already exists in the list */
for (int i = 0; (stream = streams[i]) && i < SSCG_NUM_FILE_TYPES; i++)
{
SSCG_LOG (SSCG_DEBUG,
"Checking for 0x%.4x in 0x%.4x\n",
--
2.35.1