From a20f00058486fa5dcc415616a3f6ec6179f1ee43 Mon Sep 17 00:00:00 2001 From: David Kinder Date: Wed, 16 Aug 2017 20:24:42 +0100 Subject: [PATCH] Mantis 2023: Add a limit on verb length of 120. The maximum length of a verb is now limited to 120 (which can be changed in the source code). Previously very long verbs would crash the compiler. This change is being pulled from upstream based on commit 560f49f dated Aug 16 2017. Also update the version number and the copyright years for the modified files based on this change. These changes are similiarly relicensed to GPL per Section 4(c)(ii) of the Artistic License 2.0. --- header.h | 5 +++-- verbs.c | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/header.h b/header.h index d99b75e..90715a5 100644 --- a/header.h +++ b/header.h @@ -1,7 +1,7 @@ /* ------------------------------------------------------------------------- */ /* Header file for Inform: Z-machine ("Infocom" format) compiler */ /* */ -/* Copyright (c) Graham Nelson 1993 - 2016 */ +/* Copyright (c) Graham Nelson 1993 - 2017 */ /* */ /* This file is part of Inform. */ /* */ @@ -32,7 +32,7 @@ /* */ /* ------------------------------------------------------------------------- */ -#define RELEASE_DATE "1 Oct 2016" +#define RELEASE_DATE "16 Aug 2017" #define RELEASE_NUMBER 1634 #define GLULX_RELEASE_NUMBER 38 #define MODULE_VERSION_NUMBER 1 @@ -690,6 +690,7 @@ static int32 unique_task_id(void) #define MAX_DICT_WORD_SIZE 40 #define MAX_DICT_WORD_BYTES (40*4) #define MAX_NUM_ATTR_BYTES 39 +#define MAX_VERB_WORD_SIZE 120 #define VENEER_CONSTRAINT_ON_CLASSES_Z 256 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z 128 diff --git a/verbs.c b/verbs.c index df7c304..c4e5027 100644 --- a/verbs.c +++ b/verbs.c @@ -2,7 +2,7 @@ /* "verbs" : Manages actions and grammar tables; parses the directives */ /* Verb and Extend. */ /* */ -/* Copyright (c) Graham Nelson 1993 - 2016 */ +/* Copyright (c) Graham Nelson 1993 - 2017 */ /* */ /* This file is part of Inform. */ /* */ @@ -339,21 +339,29 @@ static void register_verb(char *English_verb, int number) { /* Registers a new English verb as referring to the given Inform-verb number. (See comments above for format of the list.) */ + int entrysize; if (find_or_renumber_verb(English_verb, NULL) != -1) { error_named("Two different verb definitions refer to", English_verb); return; } - English_verb_list_size += strlen(English_verb)+4; + /* We set a hard limit of MAX_VERB_WORD_SIZE=120 because the + English_verb_list table stores length in a leading byte. (We could + raise that to 250, really, but there's little point when + MAX_DICT_WORD_SIZE is 40.) */ + entrysize = strlen(English_verb)+4; + if (entrysize > MAX_VERB_WORD_SIZE+4) + error_numbered("Verb word is too long -- max length is", MAX_VERB_WORD_SIZE); + English_verb_list_size += entrysize; if (English_verb_list_size >= MAX_VERBSPACE) memoryerror("MAX_VERBSPACE", MAX_VERBSPACE); - English_verb_list_top[0] = 4+strlen(English_verb); + English_verb_list_top[0] = entrysize; English_verb_list_top[1] = number/256; English_verb_list_top[2] = number%256; strcpy(English_verb_list_top+3, English_verb); - English_verb_list_top += English_verb_list_top[0]; + English_verb_list_top += entrysize; } static int get_verb(void) -- 2.31.1