All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jonathan Nieder <jrnieder@gmail.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>,
	Jens Lehmann <Jens.Lehmann@web.de>,
	Duy Nguyen <pclouds@gmail.com>
Subject: Re: [PATCH 01/15] string_list: add string_list_duplicate
Date: Wed, 27 Apr 2016 11:02:29 -0700	[thread overview]
Message-ID: <CAGZ79kbWMN3YG5Jtz8i8Y9A3id8bX-YxSWp19+yGAdzMX_wKKA@mail.gmail.com> (raw)
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:
> 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.

>
> 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




>
>>  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);

  reply	other threads:[~2016-04-27 18:02 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-26 20:50 [PATCH 00/15] submodule groups (once again) Stefan Beller
2016-04-26 20:50 ` [PATCH 01/15] string_list: add string_list_duplicate Stefan Beller
2016-04-26 22:37   ` Junio C Hamano
2016-04-27 18:02     ` Stefan Beller [this message]
2016-04-27 21:11       ` Junio C Hamano
2016-04-27 21:17         ` Stefan Beller
2016-04-27 23:17           ` Junio C Hamano
2016-04-27 23:24             ` Stefan Beller
2016-04-26 20:50 ` [PATCH 02/15] submodule doc: write down what we want to achieve in this series Stefan Beller
2016-04-26 22:42   ` Junio C Hamano
2016-04-26 20:50 ` [PATCH 03/15] submodule add: label submodules if asked to Stefan Beller
2016-04-26 22:49   ` Junio C Hamano
2016-04-26 22:50   ` Jacob Keller
2016-04-26 23:19     ` Stefan Beller
2016-04-27  3:24       ` Jacob Keller
2016-04-26 20:50 ` [PATCH 04/15] submodule-config: keep labels around Stefan Beller
2016-04-26 20:50 ` [PATCH 05/15] submodule-config: check if submodule a submodule is in a group Stefan Beller
2016-04-26 22:58   ` Junio C Hamano
2016-04-26 23:17     ` Junio C Hamano
2016-04-27 23:00       ` Stefan Beller
2016-04-26 20:50 ` [PATCH 06/15] submodule init: redirect stdout to stderr Stefan Beller
2016-04-29 18:27   ` Junio C Hamano
2016-04-29 18:38     ` Stefan Beller
2016-04-26 20:50 ` [PATCH 07/15] submodule deinit: loose requirement for giving '.' Stefan Beller
2016-04-29 18:27   ` Junio C Hamano
2016-04-26 20:50 ` [PATCH 08/15] submodule--helper list: respect submodule groups Stefan Beller
2016-04-29 18:31   ` Junio C Hamano
2016-04-26 20:50 ` [PATCH 09/15] submodule--helper init: " Stefan Beller
2016-04-26 20:50 ` [PATCH 10/15] submodule--helper update_clone: " Stefan Beller
2016-04-26 20:50 ` [PATCH 11/15] diff: ignore submodules excluded by groups Stefan Beller
2016-04-29 18:37   ` Junio C Hamano
2016-04-29 19:17     ` Stefan Beller
2016-05-05 19:57       ` Stefan Beller
2016-05-05 20:19         ` Junio C Hamano
2016-05-05 21:02           ` Stefan Beller
2016-05-05 22:20             ` Junio C Hamano
2016-05-05 22:50               ` Stefan Beller
2016-05-05 23:07                 ` Junio C Hamano
2016-05-06  6:08                   ` Junio C Hamano
2016-05-06 18:23                     ` Stefan Beller
2016-05-06 18:59                       ` Junio C Hamano
2016-04-26 20:50 ` [PATCH 12/15] git submodule summary respects groups Stefan Beller
2016-04-29 18:38   ` Junio C Hamano
2016-04-26 20:50 ` [PATCH 13/15] cmd_status: respect submodule groups Stefan Beller
2016-04-26 20:50 ` [PATCH 14/15] cmd_diff: " Stefan Beller
2016-04-26 20:50 ` [PATCH 15/15] clone: allow specification of submodules to be cloned Stefan Beller
2016-04-26 22:19 ` [PATCH 00/15] submodule groups (once again) Junio C Hamano
2016-04-26 22:26 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGZ79kbWMN3YG5Jtz8i8Y9A3id8bX-YxSWp19+yGAdzMX_wKKA@mail.gmail.com \
    --to=sbeller@google.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.