From patchwork Tue Oct 7 05:25:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Colascione X-Patchwork-Id: 3122 Received: (qmail 6027 invoked by alias); 7 Oct 2014 05:25:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6014 invoked by uid 89); 7 Oct 2014 05:25:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: dancol.org Received: from dancol.org (HELO dancol.org) (96.126.100.184) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 07 Oct 2014 05:25:11 +0000 Received: from [2620:0:1cfe:9a:863a:4bff:fec8:e538] by dancol.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84) (envelope-from ) id 1XbNGn-0000SV-CS for gdb-patches@sourceware.org; Mon, 06 Oct 2014 22:25:09 -0700 Message-ID: <5433792E.206@dancol.org> Date: Mon, 06 Oct 2014 22:25:02 -0700 From: Daniel Colascione User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Fix off-by-one bug calling value_cstring X-IsSubscribed: yes Sometimes we create strings that aren't NUL-terminated. diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 185b38e..0953e0d 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -660,7 +660,7 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp, else if ((dest_type & C_CHAR) != 0) result = allocate_value (type); else - result = value_cstring ("", 0, type); + result = value_cstring ("", 1, type); do_cleanups (cleanup); return result; } diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c index e05f99e..d533bf6 100644 --- a/gdb/guile/scm-math.c +++ b/gdb/guile/scm-math.c @@ -827,7 +827,7 @@ vlscm_convert_typed_value_from_scheme (const char *func_name, { cleanup = make_cleanup (xfree, s); value - = value_cstring (s, len, + = value_cstring (s, len + 1, language_string_char_type (language, gdbarch)); do_cleanups (cleanup); diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 0cefd4f..ca20921 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1601,7 +1601,7 @@ convert_value_from_python (PyObject *obj) struct cleanup *old; old = make_cleanup (xfree, s); - value = value_cstring (s, strlen (s), builtin_type_pychar); + value = value_cstring (s, strlen (s) + 1, builtin_type_pychar); do_cleanups (old); } } diff --git a/gdb/value.c b/gdb/value.c index fdc8858d..0198e03 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -2147,7 +2147,7 @@ value_of_internalvar (struct gdbarch *gdbarch, struct internalvar *var) break; case INTERNALVAR_STRING: - val = value_cstring (var->u.string, strlen (var->u.string), + val = value_cstring (var->u.string, strlen (var->u.string) + 1, builtin_type (gdbarch)->builtin_char); break;