Re: [PATCH 2/3] getpwuid(mingw): provide a better default for the user name
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Oct 16, 2018, 12:41 UTC
- Message-ID
- <CAPig+cTvKicLKZO38AcVzXJJhZ1CajOhiADotRJ0V7EJXBicUA@mail.gmail.com>
- In-Reply-To
- <nycvar.QRO.7.76.6.1810161436480.4546@tvgsbejvaqbjf.bet>
On Tue, Oct 16, 2018 at 8:38 AM Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 10 quoted lines
> On Mon, 15 Oct 2018, Eric Sunshine wrote:
> > On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget
> > <gitgitgadget@gmail.com> wrote:
> > > + len = ARRAY_SIZE(wbuffer);
> > > + if (GetUserNameExW(type, wbuffer, &len)) {
> > > + char *converted = xmalloc((len *= 3));
>
> Oh wow. I *just* realized this. It is an off-by-one: the `xmalloc()` call
> needs to receive `len + 1` to accommodate for the trailing NUL. Will fix,
> too.Or, xmallocz() (note the "z") which gives you overflow-checking of the +1 for free.