Summary: | FAIL: gdb.linespec/explicit.exp: complete after -line: cmd complete "b -line argument " (timeout) | ||
---|---|---|---|
Product: | gdb | Reporter: | Tom de Vries <vries> |
Component: | cli | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | jan, pedro |
Priority: | P2 | ||
Version: | HEAD | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Last reconfirmed: |
Description
Tom de Vries
2019-05-20 12:32:37 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>: 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, "e_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. Patch committed, marking resolved-fixed. Tom, thanks for taking care of this! I was actually working on a fix at the moment. In addition to move arg_prefix into the block, I'd also initialize word properly in complete() as: --- a/gdb/completer.c +++ b/gdb/completer.c @@ -1622,6 +1622,7 @@ complete (const char *line, char const **word, int *quote_char) completion_tracker tracker_handle_completions; completion_tracker *tracker; + *word = line; try { *word = completion_find_completion_word (tracker_handle_brkchars, or - elsewise - document that complete may leave word uninitialized in "some cases" (like, result.number_matches == 0). I prefer initializing it. This initialization alone also fixes the problem. What do you think? Shall I submit a patch with initialization in complete()? (In reply to Jan Vrany from comment #3) > Tom, > > thanks for taking care of this! > > I was actually working on a fix at the moment. In addition to move arg_prefix > into the block, I'd also initialize word properly in complete() as: > > --- a/gdb/completer.c > +++ b/gdb/completer.c > @@ -1622,6 +1622,7 @@ complete (const char *line, char const **word, int > *quote_char) > completion_tracker tracker_handle_completions; > completion_tracker *tracker; > > + *word = line; > try > { > *word = completion_find_completion_word (tracker_handle_brkchars, > > or - elsewise - document that complete may leave word uninitialized in "some > cases" (like, result.number_matches == 0). I prefer initializing it. > This initialization alone also fixes the problem. > > What do you think? Shall I submit a patch with initialization in complete()? Hi, I'd say if 'word' can be initialized to something valid, we should do so. The master branch has been updated by Jan Vrany <jv@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0ef209f22c24b9243de68c35c576f7111198f915 commit 0ef209f22c24b9243de68c35c576f7111198f915 Author: Jan Vrany <jan.vrany@fit.cvut.cz> Date: Thu May 30 13:04:26 2019 +0100 Initialize variable word in complete The complete function should set parameter word to the end of the word to complete. However, completion_find_completion_word may fail, leaving word uninitialized. To make sure word is always set, initialize it to the completion point which is the end of the line parameter. gdb/Changelog PR cli/24587 * completer.c (complete): Initialize variable word. |