$ git show --format=fuller --patch-with-stat --summary 2589381ecc2d251f64b70e30022565704fd160bd
commit 2589381ecc2d251f64b70e30022565704fd160bd
Author: Tomasz Paweł Gajc <tpgxyz@gmail.com>
AuthorDate: Wed Mar 15 14:34:49 2023 +0100
Commit: Tomasz Paweł Gajc <tpgxyz@gmail.com>
CommitDate: Wed Mar 15 14:34:49 2023 +0100
sync sources
---
.abf.yml | 2 +
0000-fix-null-pointer-dereference.patch | 151 ++++++++++++++++++++++++++++++++
aha.spec | 36 ++++++++
3 files changed, 189 insertions(+)
create mode 100644 .abf.yml
create mode 100644 0000-fix-null-pointer-dereference.patch
create mode 100644 aha.spec
diff --git a/.abf.yml b/.abf.yml
new file mode 100644
index 0000000..c5e5232
--- /dev/null
+++ b/.abf.yml
@@ -0,0 +1,2 @@
+sources:
+ aha-0.5.1.tar.gz: 1db95e69b28c46c485643c42fe0a921caf721d3e
diff --git a/0000-fix-null-pointer-dereference.patch b/0000-fix-null-pointer-dereference.patch
new file mode 100644
index 0000000..ef4206e
--- /dev/null
+++ b/0000-fix-null-pointer-dereference.patch
@@ -0,0 +1,151 @@
+From a340963e0c40f3ea85fea911c79fbaaa5af93e27 Mon Sep 17 00:00:00 2001
+From: suve <veg@svgames.pl>
+Date: Thu, 9 Jun 2022 15:46:20 +0200
+Subject: [PATCH 1/2] Check if 24-bit colour codes contain 3 arguments
+
+---
+ aha.c | 64 ++++++++++++++++++++++++++---------------------------------
+ 1 file changed, 28 insertions(+), 36 deletions(-)
+
+diff --git a/aha.c b/aha.c
+index 46e43c0..bf22373 100644
+--- a/aha.c
++++ b/aha.c
+@@ -833,25 +833,21 @@ int main(int argc,char* args[])
+ if (momelem->value == 38 &&
+ momelem->next &&
+ momelem->next->value == 2 &&
+- momelem->next->next)// 38;2;<n> -> 24 Bit
++ momelem->next->next &&
++ momelem->next->next->next &&
++ momelem->next->next->next->next)// 38;2;<r>;<g>;<b> -> 24 Bit
+ {
+- momelem = momelem->next->next;
+- pelem r,g,b;
+- r = momelem;
+- momelem = momelem->next;
+- g = momelem;
+- if ( momelem )
+- momelem = momelem->next;
+- b = momelem;
+- if ( r && g && b )
+- {
+- state.highlighted = 0;
+- state.fc_colormode = MODE_24BIT;
+- *dest =
+- (r->value & 255) * 65536 +
+- (g->value & 255) * 256 +
+- (b->value & 255);
+- }
++ pelem r = momelem->next->next;
++ pelem g = r->next;
++ pelem b = g->next;
++ momelem = b;
++
++ state.highlighted = 0;
++ state.fc_colormode = MODE_24BIT;
++ *dest =
++ (r->value & 255) * 65536 +
++ (g->value & 255) * 256 +
++ (b->value & 255);
+ }
+ else
+ {
+@@ -901,25 +897,21 @@ int main(int argc,char* args[])
+ if (momelem->value == 48 &&
+ momelem->next &&
+ momelem->next->value == 2 &&
+- momelem->next->next)// 48;2;<n> -> 24 Bit
++ momelem->next->next &&
++ momelem->next->next->next &&
++ momelem->next->next->next->next)// 48;2;<r>;<g>;<b> -> 24 Bit
+ {
+- momelem = momelem->next->next;
+- pelem r,g,b;
+- r = momelem;
+- momelem = momelem->next;
+- g = momelem;
+- if ( momelem )
+- momelem = momelem->next;
+- b = momelem;
+- if ( r && g && b )
+- {
+- state.bc_colormode = MODE_24BIT;
+- state.highlighted = 0;
+- *dest =
+- (r->value & 255) * 65536 +
+- (g->value & 255) * 256 +
+- (b->value & 255);
+- }
++ pelem r = momelem->next->next;
++ pelem g = r->next;
++ pelem b = g->next;
++ momelem = b;
++
++ state.bc_colormode = MODE_24BIT;
++ state.highlighted = 0;
++ *dest =
++ (r->value & 255) * 65536 +
++ (g->value & 255) * 256 +
++ (b->value & 255);
+ }
+ else
+ {
+
+From 1b8b994b058920cdc2fe144dca3243bacf1d49b2 Mon Sep 17 00:00:00 2001
+From: suve <veg@svgames.pl>
+Date: Thu, 9 Jun 2022 15:55:29 +0200
+Subject: [PATCH 2/2] Add a helper function to avoid ->next checks
+
+---
+ aha.c | 23 +++++++++++++----------
+ 1 file changed, 13 insertions(+), 10 deletions(-)
+
+diff --git a/aha.c b/aha.c
+index bf22373..2bfebb7 100644
+--- a/aha.c
++++ b/aha.c
+@@ -138,6 +138,15 @@ pelem parseInsert(char* s)
+ return firstelem;
+ }
+
++int parseDepthAtLeast(pelem elem, unsigned int wanted) {
++ while (elem != NULL) {
++ if (wanted == 0) return 1;
++ elem = elem->next;
++ --wanted;
++ }
++ return 0;
++}
++
+ void deleteParse(pelem elem)
+ {
+ while (elem!=NULL)
+@@ -831,11 +840,8 @@ int main(int argc,char* args[])
+ }
+ else
+ if (momelem->value == 38 &&
+- momelem->next &&
+- momelem->next->value == 2 &&
+- momelem->next->next &&
+- momelem->next->next->next &&
+- momelem->next->next->next->next)// 38;2;<r>;<g>;<b> -> 24 Bit
++ parseDepthAtLeast(momelem, 4) &&
++ momelem->next->value == 2)// 38;2;<r>;<g>;<b> -> 24 Bit
+ {
+ pelem r = momelem->next->next;
+ pelem g = r->next;
+@@ -895,11 +901,8 @@ int main(int argc,char* args[])
+ }
+ else
+ if (momelem->value == 48 &&
+- momelem->next &&
+- momelem->next->value == 2 &&
+- momelem->next->next &&
+- momelem->next->next->next &&
+- momelem->next->next->next->next)// 48;2;<r>;<g>;<b> -> 24 Bit
++ parseDepthAtLeast(momelem, 4) &&
++ momelem->next->value == 2)// 48;2;<r>;<g>;<b> -> 24 Bit
+ {
+ pelem r = momelem->next->next;
+ pelem g = r->next;
diff --git a/aha.spec b/aha.spec
new file mode 100644
index 0000000..d9e9fdc
--- /dev/null
+++ b/aha.spec
@@ -0,0 +1,36 @@
+Summary: Convert terminal output to HTML
+Name: aha
+License: MPLv1.1 or LGPLv2+
+Version: 0.5.1
+Release: 1
+Group: Text tools
+URL: https://github.com/theZiz/aha
+Source0: %{URL}/archive/%{version}/%{name}-%{version}.tar.gz
+
+# Fix a null pointer dereference when interpreting
+# invalid 24-bit color code escape sequences.
+#
+# Submitted upstream: https://github.com/theZiz/aha/pull/97
+Patch0: 0000-fix-null-pointer-dereference.patch
+
+%description
+%{name} parses output from other programs,
+recognizes ANSI terminal escape sequences
+and produces an HTML rendition of the original text.
+
+%prep
+%autosetup -p1
+# Extract license header from source code
+cat aha.c | awk '1;/\*\//{exit}' > LICENSE
+
+%build
+%set_build_flags
+%make_build
+
+%install
+%make_install PREFIX=%{_prefix}
+
+%files
+%license LICENSE
+%{_bindir}/%{name}
+%doc %{_mandir}/man1/%{name}.*