git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 01/15] string_list: add string_list_duplicate

From
Stefan Beller <sbeller@google.com>
Date
Apr 27, 2016, 18:02 UTC
Message-ID
<CAGZ79kbWMN3YG5Jtz8i8Y9A3id8bX-YxSWp19+yGAdzMX_wKKA@mail.gmail.com>
In-Reply-To
<xmqqh9eoc7zc.fsf@gitster.mtv.corp.google.com>
On Tue, Apr 26, 2016 at 3:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 11 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> The result of git_config_get_value_multi do not seem to be stable and
>> may get overwritten. Have an easy way to preserve the results of that
>> query.
>>
>> Signed-off-by: Stefan Beller <sbeller@google.com>
>> ---
>
> This morning I reviewed a patch that adds something whose name ends
> with _copy(), and this may want to follow suit.
ok, in case we need this patch, I'll rename.
Show 10 quoted lines
>
> Should strdup_strings() be a separate parameter, or should it follow
> what src->strdup_strings has?
>
> "Do not seem to be stable" does not build confidence in the code,
> making it sound as if the developer is basing his work on guess not
> analysis, and makes it hard to tell if this is a wrong workaround to
> a valid issue (e.g. it could be "making the result stable" is what
> we want in the longer term) or a valid solution to a problem that
> would be common across callers of that API.

When not duplicating git_config_get_value_multi("submodule.defaultGroup"); I run into

Program received signal SIGSEGV, Segmentation fault. 0x0000000000579097 in get_entry_index (list=0x876848, string=0x8721e0 "./submodule1", exact_match=0x7fffffffd6bc) at string-list.c:38 38 int compare = cmp(string, list->items[middle].string); (gdb) bt #0 0x0000000000579097 in get_entry_index (list=0x876848, string=0x8721e0 "./submodule1", exact_match=0x7fffffffd6bc) at string-list.c:38 #1 0x00000000005792d5 in string_list_has_string (list=0x876848, string=0x8721e0 "./submodule1") at string-list.c:91 #2 0x000000000057e78c in submodule_in_group (group=0x876848, sub=0x878510) at submodule-config.c:558 #3 0x0000000000497cf9 in module_init (argc=0, argv=0x7fffffffdb28, prefix=0x0) at builtin/submodule--helper.c:441 #4 0x00000000004993f6 in cmd_submodule__helper (argc=2, argv=0x7fffffffdb20, prefix=0x0) at builtin/submodule--helper.c:927 #5 0x000000000040582e in run_builtin (p=0x83c0c0 <commands+2400>, argc=2, argv=0x7fffffffdb20) at git.c:353 #6 0x0000000000405a1d in handle_builtin (argc=2, argv=0x7fffffffdb20) at git.c:540 #7 0x0000000000405b3f in run_argv (argcp=0x7fffffffd9fc, argv=0x7fffffffda10) at git.c:594 #8 0x0000000000405d32 in main (argc=2, av=0x7fffffffdb18) at git.c:701 (gdb) print list->items[middle].string Cannot access memory at address 0x746c006fd40bd151

So the string list seems to be corrupted here. Someone stomping over our memory? How long is the result of git_config_get_value_multi deemed to be stable and usable?

I did not find out myself how to properly answer these. So it was symptom based programming (copying that stuff makes the error go away).

This only happens in one code path, which is
        group = NULL;
        if (!pathspec.nr)
                group = //string_list_duplicate(
                        (struct string_list*)
git_config_get_value_multi("submodule.defaultGroup");//, 1);
        if (group) {
                gitmodules_config();
                for (i = 0; i < list.nr; i++) {
                        const struct submodule *sub =
                                submodule_from_path(null_sha1,
                                                    list.entries[i]->name);
                        if (submodule_in_group(group, sub))
                                init_submodule(list.entries[i]->name,
prefix, quiet);
                }
        }
        ... // group is not further used

Maybe gitmodules_config needs to be called before git_config_get_value_multi, as it changes that?

I dunno, will debug more later.

Thanks, Stefan

Show 47 quoted lines
>
>>  string-list.c | 18 ++++++++++++++++++
>>  string-list.h |  2 ++
>>  2 files changed, 20 insertions(+)
>>
>> diff --git a/string-list.c b/string-list.c
>> index 2a32a3f..f981c8a 100644
>> --- a/string-list.c
>> +++ b/string-list.c
>> @@ -7,6 +7,24 @@ void string_list_init(struct string_list *list, int strdup_strings)
>>       list->strdup_strings = strdup_strings;
>>  }
>>
>> +struct string_list *string_list_duplicate(const struct string_list *src,
>> +                                       int strdup_strings)
>> +{
>> +     struct string_list *list;
>> +     struct string_list_item *item;
>> +
>> +     if (!src)
>> +             return NULL;
>> +
>> +     list = xmalloc(sizeof(*list));
>> +     string_list_init(list, strdup_strings);
>> +     for_each_string_list_item(item, src)
>> +             string_list_append(list, item->string);
>> +
>> +     return list;
>> +}
>> +
>> +
>>  /* if there is no exact match, point to the index where the entry could be
>>   * inserted */
>>  static int get_entry_index(const struct string_list *list, const char *string,
>> diff --git a/string-list.h b/string-list.h
>> index d3809a1..1a5612f 100644
>> --- a/string-list.h
>> +++ b/string-list.h
>> @@ -19,6 +19,8 @@ struct string_list {
>>  #define STRING_LIST_INIT_DUP   { NULL, 0, 0, 1, NULL }
>>
>>  void string_list_init(struct string_list *list, int strdup_strings);
>> +struct string_list *string_list_duplicate(const struct string_list *src,
>> +                                       int strdup_strings);
>>
>>  void print_string_list(const struct string_list *p, const char *text);
>>  void string_list_clear(struct string_list *list, int free_util);
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 48 in “submodule groups (once again)”
  1. 00/15 submodule groups (once again)Stefan Beller, Apr 26, 2016
  2. 01/15 string_list: add string_list_duplicateStefan Beller, Apr 26, 2016
  3. Junio C HamanoApr 26, 2016
  4. Stefan BellerApr 27, 2016
  5. Junio C HamanoApr 27, 2016
  6. Stefan BellerApr 27, 2016
  7. Junio C HamanoApr 27, 2016
  8. Stefan BellerApr 27, 2016
  9. 02/15 submodule doc: write down what we want to achieve in this seriesStefan Beller, Apr 26, 2016
  10. Junio C HamanoApr 26, 2016
  11. 03/15 submodule add: label submodules if asked toStefan Beller, Apr 26, 2016
  12. Junio C HamanoApr 26, 2016
  13. Jacob KellerApr 26, 2016
  14. Stefan BellerApr 26, 2016
  15. Jacob KellerApr 27, 2016
  16. 04/15 submodule-config: keep labels aroundStefan Beller, Apr 26, 2016
  17. 05/15 submodule-config: check if submodule a submodule is in a groupStefan Beller, Apr 26, 2016
  18. Junio C HamanoApr 26, 2016
  19. Junio C HamanoApr 26, 2016
  20. Stefan BellerApr 27, 2016
  21. 06/15 submodule init: redirect stdout to stderrStefan Beller, Apr 26, 2016
  22. Junio C HamanoApr 29, 2016
  23. Stefan BellerApr 29, 2016
  24. 07/15 submodule deinit: loose requirement for giving '.'Stefan Beller, Apr 26, 2016
  25. Junio C HamanoApr 29, 2016
  26. 08/15 submodule--helper list: respect submodule groupsStefan Beller, Apr 26, 2016
  27. Junio C HamanoApr 29, 2016
  28. 09/15 submodule--helper init: respect submodule groupsStefan Beller, Apr 26, 2016
  29. 10/15 submodule--helper update_clone: respect submodule groupsStefan Beller, Apr 26, 2016
  30. 11/15 diff: ignore submodules excluded by groupsStefan Beller, Apr 26, 2016
  31. Junio C HamanoApr 29, 2016
  32. Stefan BellerApr 29, 2016
  33. Stefan BellerMay 5, 2016
  34. Junio C HamanoMay 5, 2016
  35. Stefan BellerMay 5, 2016
  36. Junio C HamanoMay 5, 2016
  37. Stefan BellerMay 5, 2016
  38. Junio C HamanoMay 5, 2016
  39. Junio C HamanoMay 6, 2016
  40. Stefan BellerMay 6, 2016
  41. Junio C HamanoMay 6, 2016
  42. 12/15 git submodule summary respects groupsStefan Beller, Apr 26, 2016
  43. Junio C HamanoApr 29, 2016
  44. 13/15 cmd_status: respect submodule groupsStefan Beller, Apr 26, 2016
  45. 14/15 cmd_diff: respect submodule groupsStefan Beller, Apr 26, 2016
  46. 15/15 clone: allow specification of submodules to be clonedStefan Beller, Apr 26, 2016
  47. Junio C HamanoApr 26, 2016
  48. Junio C HamanoApr 26, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.