public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/cli] Fix use of uninitialized variable in complete_command
@ 2019-05-21 14:32 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2019-05-21 14:32 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fb7806c7a49d6eb75cdbff183d10d00f75968c0f

commit fb7806c7a49d6eb75cdbff183d10d00f75968c0f
Author: Tom de Vries <tdevries@suse.de>
Date:   Tue May 21 16:32:41 2019 +0200

    [gdb/cli] Fix use of uninitialized variable in complete_command
    
    When building gdb on ubuntu 16.04 with gcc 5.4.0, and running the gdb
    testsuite we run into:
    ...
    FAIL: gdb.linespec/explicit.exp: complete after -line: \
      cmd complete "b -line argument " (timeout)
    ...
    
    The failure is reproducible outside the testsuite like this:
    ...
    $ gdb -q build/gdb/testsuite/outputs/gdb.linespec/explicit/explicit \
      -ex "complete b -line argument"
    Reading symbols from \
      build/gdb/testsuite/outputs/gdb.linespec/explicit/explicit...
    terminate called after throwing an instance of 'std::length_error'
      what():  basic_string::_M_create
      Aborted (core dumped)
    ...
    
    The problem is here in complete_command:
    ...
      completion_result result = complete (arg, &word, &quote_char);
    
      std::string arg_prefix (arg, word - arg);
    
      if (result.number_matches != 0)
    ...
    The problem is that the word variable is not initialized when
    result.number_matches == 0, but the variable is still used in the arg_prefix
    initialization.
    
    Fix this by guarding the arg_prefix initialization with the
    'result.number_matches != 0' test.
    
    Build and tested on x86_64-linux.
    
    gdb/ChangeLog:
    
    2019-05-21  Tom de Vries  <tdevries@suse.de>
    
    	PR cli/24587
    	* cli/cli-cmds.c (complete_command): Fix use of unitialized variable.

Diff:
---
 gdb/ChangeLog      | 5 +++++
 gdb/cli/cli-cmds.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 51e946f..86f522d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-21  Tom de Vries  <tdevries@suse.de>
+
+	PR cli/24587
+	* cli/cli-cmds.c (complete_command): Fix use of unitialized variable.
+
 2019-05-18  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	PR gdb/18644:
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 332078b..daf409a 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -248,10 +248,10 @@ complete_command (const char *arg, int from_tty)
 
   completion_result result = complete (arg, &word, &quote_char);
 
-  std::string arg_prefix (arg, word - arg);
-
   if (result.number_matches != 0)
     {
+      std::string arg_prefix (arg, word - arg);
+
       if (result.number_matches == 1)
 	printf_unfiltered ("%s%s\n", arg_prefix.c_str (), result.match_list[0]);
       else


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-21 14:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21 14:32 [binutils-gdb] [gdb/cli] Fix use of uninitialized variable in complete_command Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).