All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Sixt <j6t@kdbg.org>
Cc: "Sören Krecker" <soekkle@freenet.de>,
	sunshine@sunshineco.com, git@vger.kernel.org
Subject: Re: [PATCH v7 1/1] mingw: give more details about unsafe directory's ownership
Date: Tue, 09 Jan 2024 12:06:42 -0800	[thread overview]
Message-ID: <xmqq8r4ygtkd.fsf@gitster.g> (raw)
In-Reply-To: <d1e1a543-ab9c-4b1b-9f1d-3728e791df2e@kdbg.org> (Johannes Sixt's message of "Tue, 9 Jan 2024 20:27:35 +0100")

Johannes Sixt <j6t@kdbg.org> writes:

>> +	LookupAccountSidA(NULL, sid, NULL, &len_user, NULL, &len_domain,
>> +			  &pe_use); 
>
> At this point, the function fails, so len_user and len_domain contain
> the required buffer size (including the trailing NUL).

So (*str)[len_domain] would be the trailing NUL after the domain
part in the next call?  Or would that be (*str)[len_domain-1]?  I am
puzzled by off-by-one with your "including the trailing NUL" remark.

>> +	/*
>> +	 * Alloc needed space of the strings
>> +	 */
>> +	ALLOC_ARRAY((*str), (size_t)len_domain + (size_t)len_user); 

This obviously assumes for domain 'd' and user 'u', we want "d/u" and
len_domain must be 1+1 (including NUL) and len_user must be 1+1
(including NUL).  But then ...

>> +	translate_sid_to_user = LookupAccountSidA(NULL, sid,
>> +	    (*str) + len_domain, &len_user, *str, &len_domain, &pe_use);

... ((*str)+len_domain) is presumably the beginning of the user
part, and (*str)+0) is where the domain part is to be stored.

Because len_domain includes the terminating NUL for the domain part,
(*str)[len_domain-1] is that NUL, no?  And that is what you want to
overwrite to make the two strings <d> <NUL> <u> <NUL> into a single
one <d> <slash> <u> <NUL>.  So...

> At this point, if the function is successful, len_user and len_domain
> contain the lengths of the names (without the trailing NUL).
>
>> +	if (!translate_sid_to_user)
>> +		FREE_AND_NULL(*str);
>> +	else
>> +		(*str)[len_domain] = '/';

... this offset looks fishy to me.  Am I off-by-one?

> Therefore, this overwrites the NUL after the domain name and so
> concatenates the two names. Good.
>
> I found this by dumping the values of the variables, because the
> documentation of LookupAccountSid is not clear about the values that the
> variables receive in the success case.
>
>> +	return translate_sid_to_user;
>> +}
>> +
>
> This patch looks good and works for me.
>
> Acked-by: Johannes Sixt <j6t@kdbg.org>
>
> Thank you!
>
> -- Hannes

  reply	other threads:[~2024-01-09 20:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-29 12:03 [PATCH 0/1 v2] Replace SID with domain/username on Windows Sören Krecker
2023-12-29 12:03 ` [PATCH v2 1/1] Replace SID with domain/username Sören Krecker
2024-01-02 16:20   ` Junio C Hamano
2024-01-02 17:33     ` Junio C Hamano
2023-12-31  4:08 ` [PATCH 0/1 v2] Replace SID with domain/username on Windows Eric Sunshine
2023-12-31  9:12   ` [PATCH V3 0/1] " Sören Krecker
2023-12-31  9:12     ` [PATCH v3 1/1] Replace SID with domain/username Sören Krecker
2024-01-02 17:43       ` Junio C Hamano
2024-01-02 19:15         ` [PATCH V4 0/1] Replace SID with domain/username on Windows Sören Krecker
2024-01-02 19:15           ` [PATCH V4 1/1] Replace SID with domain/username Sören Krecker
2024-01-03  0:43             ` Junio C Hamano
2024-01-03  8:21               ` Matthias Aßhauer
2024-01-03 22:22                 ` Junio C Hamano
2024-01-04 19:22                 ` [PATCH v5 0/1] Replace SID with domain/username on Windows Sören Krecker
2024-01-04 19:22                   ` [PATCH v5 1/1] Adds domain/username to error message Sören Krecker
2024-01-04 20:09                     ` Junio C Hamano
2024-01-06 11:29                       ` [PATCH v6 0/1] mingw: give more details about unsafe directory's ownership Sören Krecker
2024-01-06 11:29                         ` [PATCH v6 1/1] " Sören Krecker
2024-01-07 20:02                           ` Johannes Sixt
2024-01-08 17:38                             ` [PATCH v6 0/1] mingw: give more details about unsafe directory's Sören Krecker
2024-01-08 17:38                               ` [PATCH v7 1/1] mingw: give more details about unsafe directory's ownership Sören Krecker
2024-01-08 19:18                                 ` Junio C Hamano
2024-01-09 19:27                                 ` Johannes Sixt
2024-01-09 20:06                                   ` Junio C Hamano [this message]
2024-01-09 21:05                                     ` Johannes Sixt
2024-01-09 22:34                                       ` Junio C Hamano
2024-01-08 17:51                               ` [PATCH v6 0/1] mingw: give more details about unsafe directory's Dragan Simic
2023-12-31  9:18     ` [PATCH V3 0/1] Replace SID with domain/username on Windows Eric Sunshine

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=xmqq8r4ygtkd.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=soekkle@freenet.de \
    --cc=sunshine@sunshineco.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.