aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@debian.org>2021-03-30 11:15:07 +0000
committerTatsuya Kinoshita <tats@debian.org>2021-03-30 11:15:07 +0000
commit1a9bcdf202f062e89bb73aa9b0bfe6e3c9b4d5d9 (patch)
treea7894c50d982205760ff7f15f20a9da55a240d0a
parentUpdate ChangeLog (diff)
downloadw3m-1a9bcdf202f062e89bb73aa9b0bfe6e3c9b4d5d9.tar.gz
w3m-1a9bcdf202f062e89bb73aa9b0bfe6e3c9b4d5d9.zip
Treat textlist item number as int instead of short
cf. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=838952
-rw-r--r--history.c9
-rw-r--r--history.h1
-rw-r--r--textlist.c5
-rw-r--r--textlist.h10
4 files changed, 17 insertions, 8 deletions
diff --git a/history.c b/history.c
index f2a00b4..2ba0400 100644
--- a/history.c
+++ b/history.c
@@ -119,7 +119,8 @@ unshiftHist(Hist *hist, char *ptr)
{
HistItem *item;
- if (hist == NULL || hist->list == NULL)
+ if (hist == NULL || hist->list == NULL ||
+ hist->list->nitem >= HIST_LIST_MAX)
return NULL;
item = (HistItem *)newListItem((void *)allocStr(ptr, -1),
(ListItem *)hist->list->first, NULL);
@@ -137,7 +138,8 @@ pushHist(Hist *hist, char *ptr)
{
HistItem *item;
- if (hist == NULL || hist->list == NULL)
+ if (hist == NULL || hist->list == NULL ||
+ hist->list->nitem >= HIST_LIST_MAX)
return NULL;
item = (HistItem *)newListItem((void *)allocStr(ptr, -1),
NULL, (ListItem *)hist->list->last);
@@ -157,7 +159,8 @@ pushHashHist(Hist *hist, char *ptr)
{
HistItem *item;
- if (hist == NULL || hist->list == NULL)
+ if (hist == NULL || hist->list == NULL ||
+ hist->list->nitem >= HIST_LIST_MAX)
return NULL;
item = getHashHist(hist, ptr);
if (item) {
diff --git a/history.h b/history.h
index 4c41099..e2b3bf2 100644
--- a/history.h
+++ b/history.h
@@ -5,6 +5,7 @@
#include "textlist.h"
#include "hash.h"
+#define HIST_LIST_MAX GENERAL_LIST_MAX
#define HIST_HASH_SIZE 127
typedef ListItem HistItem;
diff --git a/textlist.c b/textlist.c
index fda46eb..2026fc5 100644
--- a/textlist.c
+++ b/textlist.c
@@ -30,7 +30,7 @@ void
pushValue(GeneralList *tl, void *s)
{
ListItem *it;
- if (s == NULL)
+ if (s == NULL || tl == NULL || tl->nitem >= GENERAL_LIST_MAX)
return;
it = newListItem(s, NULL, tl->last);
if (tl->first == NULL) {
@@ -99,6 +99,9 @@ appendGeneralList(GeneralList *tl, GeneralList *tl2)
if (tl && tl2) {
if (tl2->first) {
if (tl->last) {
+ if (tl->nitem + tl2->nitem > GENERAL_LIST_MAX) {
+ return tl;
+ }
tl->last->next = tl2->first;
tl2->first->prev = tl->last;
tl->last = tl2->last;
diff --git a/textlist.h b/textlist.h
index f28b199..654adfb 100644
--- a/textlist.h
+++ b/textlist.h
@@ -2,6 +2,8 @@
#ifndef TEXTLIST_H
#define TEXTLIST_H
#include "Str.h"
+#include <limits.h>
+#define GENERAL_LIST_MAX (INT_MAX / 32)
/* General doubly linked list */
@@ -14,7 +16,7 @@ typedef struct _listitem {
typedef struct _generallist {
ListItem *first;
ListItem *last;
- short nitem;
+ int nitem;
} GeneralList;
extern ListItem *newListItem(void *s, ListItem *n, ListItem *p);
@@ -36,7 +38,7 @@ typedef struct _textlistitem {
typedef struct _textlist {
TextListItem *first;
TextListItem *last;
- short nitem;
+ int nitem;
} TextList;
#define newTextList() ((TextList *)newGeneralList())
@@ -50,7 +52,7 @@ typedef struct _textlist {
typedef struct _TextLine {
Str line;
- short pos;
+ int pos;
} TextLine;
typedef struct _textlinelistitem {
@@ -62,7 +64,7 @@ typedef struct _textlinelistitem {
typedef struct _textlinelist {
TextLineListItem *first;
TextLineListItem *last;
- short nitem;
+ int nitem;
} TextLineList;
extern TextLine *newTextLine(Str line, int pos);