This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix off-by-one bug calling value_cstring


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;


Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]