]> git.eshelyaron.com Git - emacs.git/commitdiff
Robustify checking of shorthand-shorthands
authorJoão Távora <joaotavora@gmail.com>
Sun, 20 Sep 2020 11:01:05 +0000 (12:01 +0100)
committerJoão Távora <joaotavora@gmail.com>
Wed, 22 Sep 2021 10:33:55 +0000 (11:33 +0100)
* src/lread.c (oblookup_considering_shorthand): Maybe warn when we
find fishy shorthand-shorthands.

src/lread.c

index f7d0a8c5ea9e1290c03920c27f1bd09f34d546c7..33a7bd002352c502d7ff8c43d131971bbf00da90 100644 (file)
@@ -4553,19 +4553,30 @@ oblookup (Lisp_Object obarray, register const char *ptr, ptrdiff_t size, ptrdiff
 Lisp_Object
 oblookup_considering_shorthand (Lisp_Object obarray, Lisp_Object* string)
 {
+  Lisp_Object original = *string; /* Save pointer to original string... */
   Lisp_Object tail = Vshorthand_shorthands;
   FOR_EACH_TAIL_SAFE(tail)
     {
       Lisp_Object pair = XCAR (tail);
+      if (!CONSP (pair)) goto undo;
       Lisp_Object shorthand = XCAR (pair);
       Lisp_Object longhand = XCDR (pair);
-      CHECK_STRING (shorthand);
-      CHECK_STRING (longhand);
-      Lisp_Object match = Fstring_match(shorthand, *string, Qnil);
+      if (!STRINGP (shorthand) || !STRINGP (longhand)) goto undo;
+      Lisp_Object match = Fstring_match (shorthand, *string, Qnil);
       if (!NILP(match)){
         *string = Freplace_match(longhand, Qnil, Qnil, *string, Qnil);
       }
     }
+  goto fine;
+ undo:
+  {
+    static const char* warn =
+      "Fishy value of `shorthand-shorthands'.  "
+      "Consider reviewing before evaluating code.";
+    message_dolog (warn, sizeof(warn), 0, 0);
+    *string = original;   /* ...so we can any failed trickery here. */
+  }
+ fine:
   return oblookup(obarray, SSDATA (*string), SCHARS (*string), SBYTES (*string));
 }