From 5386f9d8580e31f3f0347081ac4d3586e0f2a6b7 Mon Sep 17 00:00:00 2001 From: liyuan Date: Fri, 20 Oct 2023 07:54:45 +0800 Subject: [PATCH] backport Gracefully handle missing indirect info nodes --- ...y-handle-missing-indirect-info-nodes.patch | 136 ++++++++++++++++++ pinfo.spec | 6 +- 2 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 0001-Gracefully-handle-missing-indirect-info-nodes.patch diff --git a/0001-Gracefully-handle-missing-indirect-info-nodes.patch b/0001-Gracefully-handle-missing-indirect-info-nodes.patch new file mode 100644 index 0000000..db990ce --- /dev/null +++ b/0001-Gracefully-handle-missing-indirect-info-nodes.patch @@ -0,0 +1,136 @@ +From 1cd20619e5f5e11a9547f0a9a92853ea73c617fb Mon Sep 17 00:00:00 2001 +From: Bas Zoetekouw +Date: Sat, 27 Dec 2014 16:25:35 +0100 +Subject: [PATCH] Gracefully handle missing indirect info nodes Fixed Debian + bug https://bugs.debian.org/298865 + +--- + src/filehandling_functions.c | 37 +++++++++++++++++++++++++++--------- + src/filehandling_functions.h | 2 +- + src/pinfo.c | 11 +++++++++-- + 3 files changed, 38 insertions(+), 12 deletions(-) + +diff --git a/src/filehandling_functions.c b/src/filehandling_functions.c +index 100c4d0..b146ef0 100644 +--- a/src/filehandling_functions.c ++++ b/src/filehandling_functions.c +@@ -1099,12 +1099,27 @@ create_indirect_tag_table() + { + id = openinfo(indirect[i].filename, 1); + initial = TagTableEntries + 1; +- if (id) ++ if (!id) + { +- create_tag_table(id); +- FirstNodeOffset = tag_table[1].offset; +- strcpy(FirstNodeName, tag_table[1].nodename); ++ /* display error message to make the user aware of ++ * the broken info page ++ */ ++ char msg[81]; ++ snprintf(msg, 81, "%s '%s' (%s)", ++ _("Can't open file"), indirect[i].filename, ++ _("press a key to continue") ); ++ attrset(bottomline); ++ mvhline(maxy - 1, 0, ' ', maxx); ++ mvaddstr(maxy - 1, 0, msg); ++ move(0, 0); ++ attrset(normal); ++ getch(); ++ ++ continue; + } ++ create_tag_table(id); ++ FirstNodeOffset = tag_table[1].offset; ++ strcpy(FirstNodeName, tag_table[1].nodename); + fclose(id); + for (j = initial; j <= TagTableEntries; j++) + { +@@ -1187,10 +1202,11 @@ create_tag_table(FILE * id) + } + } + +-void ++int + seeknode(int tag_table_pos, FILE ** Id) + { + int i; ++ FILE * newid; + #define id (*Id) + /* + * Indirect nodes are seeked using a formula: +@@ -1204,15 +1220,17 @@ seeknode(int tag_table_pos, FILE ** Id) + if (indirect[i].offset <= tag_table[tag_table_pos].offset) + { + long off = tag_table[tag_table_pos].offset - indirect[i].offset + FirstNodeOffset - 4; +- fclose(id); +- id = openinfo(indirect[i].filename, 0); +- if (id == NULL) ++ newid = openinfo(indirect[i].filename, 0); ++ if (newid == NULL) + { ++ return -1; + closeprogram(); +- printf(_("Error: could not open info file")); ++ printf(_("Error: could not open info file part")); + printf("\n"); + exit(1); + } ++ fclose(id); ++ id = newid; + if (off > 0) + fseek(id, off, SEEK_SET); + else +@@ -1230,6 +1248,7 @@ seeknode(int tag_table_pos, FILE ** Id) + fseek(id, off, SEEK_SET); + } + #undef id ++ return 0; + } + + /* removes trailing .gz, .bz2, etc. */ +diff --git a/src/filehandling_functions.h b/src/filehandling_functions.h +index 3d16f41..8501482 100644 +--- a/src/filehandling_functions.h ++++ b/src/filehandling_functions.h +@@ -36,7 +36,7 @@ void initpaths (); + void addrawpath (char *filename); + + /* seek to a node in certain info file */ +-void seeknode (int tag_table_pos, FILE ** Id); ++int seeknode (int tag_table_pos, FILE ** Id); + + /* + * free allocated memory, hold by buf (node** content, stored line by line), +diff --git a/src/pinfo.c b/src/pinfo.c +index eb23624..efe01b0 100644 +--- a/src/pinfo.c ++++ b/src/pinfo.c +@@ -378,7 +378,14 @@ main(int argc, char *argv[]) + do + { + /* set seek offset for given node */ +- seeknode(tag_table_pos, &id); ++ if (seeknode(tag_table_pos, &id)!=0) ++ { ++ tag_table_pos = gettagtablepos(FirstNodeName); ++ if (seeknode(tag_table_pos, &id)!=0) ++ { ++ exit(-1); ++ } ++ } + /* read the node */ + read_item(id, &type, &message, &lines); + +@@ -415,7 +422,7 @@ main(int argc, char *argv[]) + * the broken info page + */ + char msg[81]; +- snprintf(msg, 81, "%s (%s)", ++ snprintf(msg, 81, "%s (%s)", + _("Tag table is corrupt, trying to fix..."), + _("press a key to continue") ); + attrset(bottomline); +-- +2.33.0 + diff --git a/pinfo.spec b/pinfo.spec index 2708775..134ad0e 100644 --- a/pinfo.spec +++ b/pinfo.spec @@ -1,6 +1,6 @@ Name: pinfo Version: 0.6.10 -Release: 22 +Release: 23 Summary: An user-friendly, console-based viewer for Info documents License: GPLv2 URL: http://pinfo.alioth.debian.org @@ -11,6 +11,7 @@ Patch0003: pinfo-0.6.9-nogroup.patch Patch0004: pinfo-0.6.9-mansection.patch Patch0005: pinfo-0.6.9-infopath.patch Patch0006: pinfo-0.6.10-man.patch +Patch0007: 0001-Gracefully-handle-missing-indirect-info-nodes.patch BuildRequires: ncurses-devel automake gettext-devel libtool texinfo Requires: xdg-utils @@ -52,5 +53,8 @@ Pinfo-help provides man pages and other related help documents for pinfo. %{_mandir}/man1/pinfo.1* %changelog +* Thu Oct 26 2023 liyuanyuan - 0.6.10-23 +- Gracefully handle missing indirect info nodes + * Fri Feb 14 2020 lingsheng - 0.6.10-22 - Package init