This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid leak/crash calling CORE::foo()
[perl5.git] / dquote.c
index 7070244..bf5cf90 100644 (file)
--- a/dquote.c
+++ b/dquote.c
@@ -106,7 +106,7 @@ Perl_grok_bslash_o(pTHX_ char **s, const char * const send, UV *uv,
     assert(* *s       == 'o');
     (*s)++;
 
-    if (**s != '{') {
+    if (send <= *s || **s != '{') {
        *error_msg = "Missing braces on \\o{}";
        return FALSE;
     }
@@ -210,8 +210,21 @@ Perl_grok_bslash_x(pTHX_ char **s, const char * const send, UV *uv,
 
     assert(*(*s - 1) == '\\');
     assert(* *s      == 'x');
+
     (*s)++;
 
+    if (send <= *s) {
+        if (strict) {
+            *error_msg = "Empty \\x";
+            return FALSE;
+        }
+
+        /* Sadly, to preserve backcompat, an empty \x at the end of string is
+         * interpreted as a NUL */
+        *uv = 0;
+        return TRUE;
+    }
+
     if (strict || ! output_warning) {
         flags |= PERL_SCAN_SILENT_ILLDIGIT;
     }
@@ -253,7 +266,7 @@ Perl_grok_bslash_x(pTHX_ char **s, const char * const send, UV *uv,
     if (numbers_len == 0) {
         if (strict) {
             (*s)++;    /* Move past the } */
-            *error_msg = "Number with no digits";
+            *error_msg = "Empty \\x{}";
             return FALSE;
         }
         *s = e + 1;