{"thread":{"id":"49567","subject":"[PATCH 0/3] Provide a useful default user ident on Windows","startedAt":"2018-10-15T09:47:06Z","lastAt":"2018-10-16T13:06:38Z","messageCount":12,"participants":["Johannes Schindelin via GitGitGadget","Eric Sunshine","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"360488","messageId":"pull.45.git.gitgitgadget@gmail.com","threadId":"49567","inReplyTo":null,"subject":"[PATCH 0/3] Provide a useful default user ident on Windows","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-10-15T09:47:03Z","receivedAt":"2018-10-15T09:47:06Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"On Linux, we use the gecos information to come up with a sensible user\nname/email. On Windows, there is no gecos. But there is something\ncomparable, and with these patches, we use it.\n\nThis has been carried in Git for Windows for three years, and is considered\nmature.\n\nJohannes Schindelin (3):\n  getpwuid(mingw): initialize the structure only once\n  getpwuid(mingw): provide a better default for the user name\n  mingw: use domain information for default email\n\n compat/mingw.c    | 60 +++++++++++++++++++++++++++++++++++++++++------\n compat/mingw.h    |  2 ++\n git-compat-util.h |  4 ++++\n ident.c           |  3 +++\n 4 files changed, 62 insertions(+), 7 deletions(-)\n\n\nbase-commit: 5a0cc8aca797dbd7d2be3b67458ff880ed45cddf\nPublished-As: https://github.com/gitgitgadget/git/releases/tags/pr-45%2Fdscho%2Fdefault-ident-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-45/dscho/default-ident-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/45\n-- \ngitgitgadget\n"},{"id":"360489","messageId":"63373dd91d0be324273ab34ff49d630453954173.1539596822.git.gitgitgadget@gmail.com","threadId":"49567","inReplyTo":"pull.45.git.gitgitgadget@gmail.com","subject":"[PATCH 1/3] getpwuid(mingw): initialize the structure only once","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-10-15T09:47:05Z","receivedAt":"2018-10-15T09:47:08Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n compat/mingw.c | 25 ++++++++++++++++++-------\n 1 file changed, 18 insertions(+), 7 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 18caf21969..597781b370 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1800,16 +1800,27 @@ int mingw_getpagesize(void)\n \n struct passwd *getpwuid(int uid)\n {\n+\tstatic unsigned initialized;\n \tstatic char user_name[100];\n-\tstatic struct passwd p;\n+\tstatic struct passwd *p;\n+\tDWORD len;\n \n-\tDWORD len = sizeof(user_name);\n-\tif (!GetUserName(user_name, &len))\n+\tif (initialized)\n+\t\treturn p;\n+\n+\tlen = sizeof(user_name);\n+\tif (!GetUserName(user_name, &len)) {\n+\t\tinitialized = 1;\n \t\treturn NULL;\n-\tp.pw_name = user_name;\n-\tp.pw_gecos = \"unknown\";\n-\tp.pw_dir = NULL;\n-\treturn &p;\n+\t}\n+\n+\tp = xmalloc(sizeof(*p));\n+\tp->pw_name = user_name;\n+\tp->pw_gecos = \"unknown\";\n+\tp->pw_dir = NULL;\n+\n+\tinitialized = 1;\n+\treturn p;\n }\n \n static HANDLE timer_event;\n-- \ngitgitgadget\n\n"},{"id":"360490","messageId":"11025b1639785577924b2020fb20d076308e9c69.1539596822.git.gitgitgadget@gmail.com","threadId":"49567","inReplyTo":"pull.45.git.gitgitgadget@gmail.com","subject":"[PATCH 2/3] getpwuid(mingw): provide a better default for the user name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-10-15T09:47:06Z","receivedAt":"2018-10-15T09:47:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWe do have the excellent GetUserInfoEx() function to obtain more\ndetailed information of the current user (if the user is part of a\nWindows domain); Let's use it.\n\nSuggested by Lutz Roeder.\n\nTo avoid the cost of loading Secur32.dll (even lazily, loading DLLs\ntakes a non-neglibile amount of time), we use the established technique\nto load DLLs only when, and if, needed.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n compat/mingw.c | 32 +++++++++++++++++++++++++++++++-\n 1 file changed, 31 insertions(+), 1 deletion(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 597781b370..623ff5daf5 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -5,6 +5,7 @@\n #include \"../strbuf.h\"\n #include \"../run-command.h\"\n #include \"../cache.h\"\n+#include \"win32/lazyload.h\"\n \n #define HCAST(type, handle) ((type)(intptr_t)handle)\n \n@@ -1798,6 +1799,33 @@ int mingw_getpagesize(void)\n \treturn si.dwAllocationGranularity;\n }\n \n+/* See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435.aspx */\n+enum EXTENDED_NAME_FORMAT {\n+\tNameDisplay = 3,\n+\tNameUserPrincipal = 8\n+};\n+\n+static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)\n+{\n+\tDECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW,\n+\t\tenum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG);\n+\tstatic wchar_t wbuffer[1024];\n+\tDWORD len;\n+\n+\tif (!INIT_PROC_ADDR(GetUserNameExW))\n+\t\treturn NULL;\n+\n+\tlen = ARRAY_SIZE(wbuffer);\n+\tif (GetUserNameExW(type, wbuffer, &len)) {\n+\t\tchar *converted = xmalloc((len *= 3));\n+\t\tif (xwcstoutf(converted, wbuffer, len) >= 0)\n+\t\t\treturn converted;\n+\t\tfree(converted);\n+\t}\n+\n+\treturn NULL;\n+}\n+\n struct passwd *getpwuid(int uid)\n {\n \tstatic unsigned initialized;\n@@ -1816,7 +1844,9 @@ struct passwd *getpwuid(int uid)\n \n \tp = xmalloc(sizeof(*p));\n \tp->pw_name = user_name;\n-\tp->pw_gecos = \"unknown\";\n+\tp->pw_gecos = get_extended_user_info(NameDisplay);\n+\tif (!p->pw_gecos)\n+\t\tp->pw_gecos = \"unknown\";\n \tp->pw_dir = NULL;\n \n \tinitialized = 1;\n-- \ngitgitgadget\n\n"},{"id":"360491","messageId":"271a5f57cef00d24ee33e99839cf3890e561efe7.1539596822.git.gitgitgadget@gmail.com","threadId":"49567","inReplyTo":"pull.45.git.gitgitgadget@gmail.com","subject":"[PATCH 3/3] mingw: use domain information for default email","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-10-15T09:47:08Z","receivedAt":"2018-10-15T09:47:11Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWhen a user is registered in a Windows domain, it is really easy to\nobtain the email address. So let's do that.\n\nSuggested by Lutz Roeder.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n compat/mingw.c    | 5 +++++\n compat/mingw.h    | 2 ++\n git-compat-util.h | 4 ++++\n ident.c           | 3 +++\n 4 files changed, 14 insertions(+)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 623ff5daf5..44264fe3fd 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1826,6 +1826,11 @@ static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)\n \treturn NULL;\n }\n \n+char *mingw_query_user_email(void)\n+{\n+\treturn get_extended_user_info(NameUserPrincipal);\n+}\n+\n struct passwd *getpwuid(int uid)\n {\n \tstatic unsigned initialized;\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 571019d0bd..f31dcff2be 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -424,6 +424,8 @@ static inline void convert_slashes(char *path)\n int mingw_offset_1st_component(const char *path);\n #define offset_1st_component mingw_offset_1st_component\n #define PATH_SEP ';'\n+extern char *mingw_query_user_email(void);\n+#define query_user_email mingw_query_user_email\n #if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)\n #define PRIuMAX \"I64u\"\n #define PRId64 \"I64d\"\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 5f2e90932f..71779cb0ae 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -382,6 +382,10 @@ static inline char *git_find_last_dir_sep(const char *path)\n #define find_last_dir_sep git_find_last_dir_sep\n #endif\n \n+#ifndef query_user_email\n+#define query_user_email() NULL\n+#endif\n+\n #if defined(__HP_cc) && (__HP_cc >= 61000)\n #define NORETURN __attribute__((noreturn))\n #define NORETURN_PTR\ndiff --git a/ident.c b/ident.c\nindex 327abe557f..33bcf40644 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -168,6 +168,9 @@ const char *ident_default_email(void)\n \t\t\tstrbuf_addstr(&git_default_email, email);\n \t\t\tcommitter_ident_explicitly_given |= IDENT_MAIL_GIVEN;\n \t\t\tauthor_ident_explicitly_given |= IDENT_MAIL_GIVEN;\n+\t\t} else if ((email = query_user_email()) && email[0]) {\n+\t\t\tstrbuf_addstr(&git_default_email, email);\n+\t\t\tfree((char *)email);\n \t\t} else\n \t\t\tcopy_email(xgetpwuid_self(&default_email_is_bogus),\n \t\t\t\t   &git_default_email, &default_email_is_bogus);\n-- \ngitgitgadget\n"},{"id":"360525","messageId":"CAPig+cS3Bz3uaxWv23bQEXB7Ok=Q+V07mGc-Fysg-WU3DKKagA@mail.gmail.com","threadId":"49567","inReplyTo":"63373dd91d0be324273ab34ff49d630453954173.1539596822.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/3] getpwuid(mingw): initialize the structure only once","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-10-15T14:25:52Z","receivedAt":"2018-10-15T14:26:06Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> diff --git a/compat/mingw.c b/compat/mingw.c\n> @@ -1800,16 +1800,27 @@ int mingw_getpagesize(void)\n>  struct passwd *getpwuid(int uid)\n>  {\n> +       static unsigned initialized;\n>         static char user_name[100];\n> -       static struct passwd p;\n> +       static struct passwd *p;\n>\n> +       if (initialized)\n> +               return p;\n> +\n> +       len = sizeof(user_name);\n> +       if (!GetUserName(user_name, &len)) {\n> +               initialized = 1;\n>                 return NULL;\n> +       }\n\nIf GetUserName() fails, that failure is recorded (as \"initialized=1\"\nand 'p' is still NULL), so subsequent invocations just return NULL\nwithout doing any more work. Makes sense.\n\n> +       p = xmalloc(sizeof(*p));\n> +       p->pw_name = user_name;\n> +       p->pw_gecos = \"unknown\";\n> +       p->pw_dir = NULL;\n> +\n> +       initialized = 1;\n> +       return p;\n>  }\n"},{"id":"360526","messageId":"CAPig+cRbOOrC5_jCnR2ohMZWoYXfNqvWtj3m_JTpudJhV1mQng@mail.gmail.com","threadId":"49567","inReplyTo":"11025b1639785577924b2020fb20d076308e9c69.1539596822.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 2/3] getpwuid(mingw): provide a better default for the user name","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-10-15T14:34:22Z","receivedAt":"2018-10-15T14:34:35Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n> We do have the excellent GetUserInfoEx() function to obtain more\n> detailed information of the current user (if the user is part of a\n> Windows domain); Let's use it.\n> [...]\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> diff --git a/compat/mingw.c b/compat/mingw.c\n> @@ -1798,6 +1799,33 @@ int mingw_getpagesize(void)\n> +static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)\n> +{\n> +       DECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW,\n> +               enum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG);\n> +       static wchar_t wbuffer[1024];\n\nDoes this need to be static? It's not being returned to the caller.\n\n> +       len = ARRAY_SIZE(wbuffer);\n> +       if (GetUserNameExW(type, wbuffer, &len)) {\n> +               char *converted = xmalloc((len *= 3));\n> +               if (xwcstoutf(converted, wbuffer, len) >= 0)\n> +                       return converted;\n> +               free(converted);\n> +       }\n\nIf xwcstoutf() fails, 'converted' is freed; otherwise, the allocated\n'converted' is stored in the caller's statically held 'passwd' struct.\nOkay.\n\n> +       return NULL;\n> +}\n"},{"id":"360528","messageId":"CAPig+cRaBRP9f3sR8suZxC+Y2_UZaBMbMcpjsRUY+mGN+nyXkQ@mail.gmail.com","threadId":"49567","inReplyTo":"271a5f57cef00d24ee33e99839cf3890e561efe7.1539596822.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 3/3] mingw: use domain information for default email","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-10-15T14:41:51Z","receivedAt":"2018-10-15T14:42:04Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n> When a user is registered in a Windows domain, it is really easy to\n> obtain the email address. So let's do that.\n> [...]\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> diff --git a/compat/mingw.c b/compat/mingw.c\n> @@ -1826,6 +1826,11 @@ static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)\n> +char *mingw_query_user_email(void)\n> +{\n> +       return get_extended_user_info(NameUserPrincipal);\n> +}\n> diff --git a/ident.c b/ident.c\n> @@ -168,6 +168,9 @@ const char *ident_default_email(void)\n> +               } else if ((email = query_user_email()) && email[0]) {\n> +                       strbuf_addstr(&git_default_email, email);\n> +                       free((char *)email);\n\nIf query_user_email(), which calls get_extended_user_info(), returns\nNULL, then we do nothing (and don't worry about freeing the result).\nHowever, if query_user_email() returns a zero-length allocated string,\nthen this conditional will leak that string (due to the email[0]\ncheck). From patch 2/3, we see in get_extended_user_info():\n\n+static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)\n+{\n+       if (GetUserNameExW(type, wbuffer, &len)) {\n+               char *converted = xmalloc((len *= 3));\n+               if (xwcstoutf(converted, wbuffer, len) >= 0)\n+                       return converted;\n\nthat it may possibly return a zero-length string (due to the \">=0\").\nDo we care about this potential leak (or is GetUserNameExW()\nguaranteed never to return such a string)?\n"},{"id":"360573","messageId":"xmqqbm7u35kb.fsf@gitster-ct.c.googlers.com","threadId":"49567","inReplyTo":"271a5f57cef00d24ee33e99839cf3890e561efe7.1539596822.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 3/3] mingw: use domain information for default email","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-10-16T03:59:16Z","receivedAt":"2018-10-16T03:59:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> +char *mingw_query_user_email(void)\n> +{\n> +\treturn get_extended_user_info(NameUserPrincipal);\n> +}\n> +\n> ...\n>  \n> +#ifndef query_user_email\n> +#define query_user_email() NULL\n> +#endif\n\nThe three patches look sensible to me; will queue.\n\nYou may already have audited our use of \"struct passwd\",\n\"getpwnam()\" and \"getpwuid()\"--I haven't.  I think we use these only\nto learn user's email (to be used as the default ident) and home\ndirectory (to expand \"git config --type=path\").  If that is really\nthe case, it may be a worthwhile clean-up to introduce our own API\nthat offers these two exact functions, have the per-platform\nimplementation of the API in compat/, and get rid of \"struct passwd\"\nand calls to getpw*() functions out of the core Git proper, to wean\nourselves away from depending on POSIX too much.\n\nBut of course that is a separate topic.\n"},{"id":"360614","messageId":"nycvar.QRO.7.76.6.1810161433220.4546@tvgsbejvaqbjf.bet","threadId":"49567","inReplyTo":"CAPig+cRaBRP9f3sR8suZxC+Y2_UZaBMbMcpjsRUY+mGN+nyXkQ@mail.gmail.com","subject":"Re: [PATCH 3/3] mingw: use domain information for default email","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-10-16T12:34:04Z","receivedAt":"2018-10-16T12:34:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Eric,\n\nOn Mon, 15 Oct 2018, Eric Sunshine wrote:\n\n> On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n> > When a user is registered in a Windows domain, it is really easy to\n> > obtain the email address. So let's do that.\n> > [...]\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> > diff --git a/compat/mingw.c b/compat/mingw.c\n> > @@ -1826,6 +1826,11 @@ static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)\n> > +char *mingw_query_user_email(void)\n> > +{\n> > +       return get_extended_user_info(NameUserPrincipal);\n> > +}\n> > diff --git a/ident.c b/ident.c\n> > @@ -168,6 +168,9 @@ const char *ident_default_email(void)\n> > +               } else if ((email = query_user_email()) && email[0]) {\n> > +                       strbuf_addstr(&git_default_email, email);\n> > +                       free((char *)email);\n> \n> If query_user_email(), which calls get_extended_user_info(), returns\n> NULL, then we do nothing (and don't worry about freeing the result).\n> However, if query_user_email() returns a zero-length allocated string,\n> then this conditional will leak that string (due to the email[0]\n> check). From patch 2/3, we see in get_extended_user_info():\n> \n> +static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)\n> +{\n> +       if (GetUserNameExW(type, wbuffer, &len)) {\n> +               char *converted = xmalloc((len *= 3));\n> +               if (xwcstoutf(converted, wbuffer, len) >= 0)\n> +                       return converted;\n> \n> that it may possibly return a zero-length string (due to the \">=0\").\n> Do we care about this potential leak (or is GetUserNameExW()\n> guaranteed never to return such a string)?\n\nQuite honestly, I think that this is so rare an instance (if it *can*\nhappen at all) that I simply don't care ;-)\n\nCiao,\nDscho\n"},{"id":"360615","messageId":"nycvar.QRO.7.76.6.1810161436480.4546@tvgsbejvaqbjf.bet","threadId":"49567","inReplyTo":"CAPig+cRbOOrC5_jCnR2ohMZWoYXfNqvWtj3m_JTpudJhV1mQng@mail.gmail.com","subject":"Re: [PATCH 2/3] getpwuid(mingw): provide a better default for the user name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-10-16T12:38:09Z","receivedAt":"2018-10-16T12:38:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Eric,\n\nOn Mon, 15 Oct 2018, Eric Sunshine wrote:\n\n> On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n> > We do have the excellent GetUserInfoEx() function to obtain more\n> > detailed information of the current user (if the user is part of a\n> > Windows domain); Let's use it.\n> > [...]\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> > diff --git a/compat/mingw.c b/compat/mingw.c\n> > @@ -1798,6 +1799,33 @@ int mingw_getpagesize(void)\n> > +static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)\n> > +{\n> > +       DECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW,\n> > +               enum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG);\n> > +       static wchar_t wbuffer[1024];\n> \n> Does this need to be static? It's not being returned to the caller.\n\nIt does not. Fixed.\n\n> > +       len = ARRAY_SIZE(wbuffer);\n> > +       if (GetUserNameExW(type, wbuffer, &len)) {\n> > +               char *converted = xmalloc((len *= 3));\n\nOh wow. I *just* realized this. It is an off-by-one: the `xmalloc()` call\nneeds to receive `len + 1` to accommodate for the trailing NUL. Will fix,\ntoo.\n\nCiao,\nDscho\n\n> > +               if (xwcstoutf(converted, wbuffer, len) >= 0)\n> > +                       return converted;\n> > +               free(converted);\n> > +       }\n> \n> If xwcstoutf() fails, 'converted' is freed; otherwise, the allocated\n> 'converted' is stored in the caller's statically held 'passwd' struct.\n> Okay.\n> \n> > +       return NULL;\n> > +}\n> \n"},{"id":"360616","messageId":"CAPig+cTvKicLKZO38AcVzXJJhZ1CajOhiADotRJ0V7EJXBicUA@mail.gmail.com","threadId":"49567","inReplyTo":"nycvar.QRO.7.76.6.1810161436480.4546@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 2/3] getpwuid(mingw): provide a better default for the user name","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-10-16T12:41:30Z","receivedAt":"2018-10-16T12:41:43Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Oct 16, 2018 at 8:38 AM Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> On Mon, 15 Oct 2018, Eric Sunshine wrote:\n> > On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget\n> > <gitgitgadget@gmail.com> wrote:\n> > > +       len = ARRAY_SIZE(wbuffer);\n> > > +       if (GetUserNameExW(type, wbuffer, &len)) {\n> > > +               char *converted = xmalloc((len *= 3));\n>\n> Oh wow. I *just* realized this. It is an off-by-one: the `xmalloc()` call\n> needs to receive `len + 1` to accommodate for the trailing NUL. Will fix,\n> too.\n\nOr, xmallocz() (note the \"z\") which gives you overflow-checking of the\n+1 for free.\n"},{"id":"360622","messageId":"nycvar.QRO.7.76.6.1810161506230.4546@tvgsbejvaqbjf.bet","threadId":"49567","inReplyTo":"CAPig+cTvKicLKZO38AcVzXJJhZ1CajOhiADotRJ0V7EJXBicUA@mail.gmail.com","subject":"Re: [PATCH 2/3] getpwuid(mingw): provide a better default for the user name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-10-16T13:06:35Z","receivedAt":"2018-10-16T13:06:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Eric,\n\nOn Tue, 16 Oct 2018, Eric Sunshine wrote:\n\n> On Tue, Oct 16, 2018 at 8:38 AM Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> > On Mon, 15 Oct 2018, Eric Sunshine wrote:\n> > > On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget\n> > > <gitgitgadget@gmail.com> wrote:\n> > > > +       len = ARRAY_SIZE(wbuffer);\n> > > > +       if (GetUserNameExW(type, wbuffer, &len)) {\n> > > > +               char *converted = xmalloc((len *= 3));\n> >\n> > Oh wow. I *just* realized this. It is an off-by-one: the `xmalloc()` call\n> > needs to receive `len + 1` to accommodate for the trailing NUL. Will fix,\n> > too.\n> \n> Or, xmallocz() (note the \"z\") which gives you overflow-checking of the\n> +1 for free.\n\nVery good point! Thanks for the suggestion,\nDscho\n"}]}