From 3892b95750b6aa5ed4328a287068f7cdfb9e55bc Mon Sep 17 00:00:00 2001
From: Kurt Roeckx <kurt@roeckx.be>
Date: Sat, 4 Jun 2016 16:25:39 +0200
Subject: [PATCH] Avoid creating an illegal pointer

Found by tis-interpreter

Reviewed-by: Rich Salz <rsalz@openssl.org>

GH: #1164
---
 crypto/x509/x_name.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/crypto/x509/x_name.c b/crypto/x509/x_name.c
index f0b35fb4fa..5c624cbd17 100644
--- a/crypto/x509/x_name.c
+++ b/crypto/x509/x_name.c
@@ -396,10 +396,10 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
         len--;
     }
 
-    to = from + len - 1;
+    to = from + len;
 
     /* Ignore trailing spaces */
-    while ((len > 0) && !(*to & 0x80) && isspace(*to)) {
+    while ((len > 0) && !(to[-1] & 0x80) && isspace(to[-1])) {
         to--;
         len--;
     }
-- 
2.40.0