Mantis 2023: Add a limit on verb length of 120.
authorDavid Kinder <david.kinder@david.kinder>
Wed, 16 Aug 2017 19:24:42 +0000 (20:24 +0100)
committerJason Self <j@jxself.org>
Tue, 12 Sep 2017 03:22:41 +0000 (20:22 -0700)
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
verbs.c

index d99b75e99415a90312ccbd29cc2992f2cb682051..90715a5785a0f1042dd703d125ebcf4a779042b0 100644 (file)
--- 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 df7c304acf1f420499d94e30d7d2f417a803d199..c4e5027a329e3c204c5f0d1e9215800ec23cda3d 100644 (file)
--- 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)