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

Re: [PATCH 3/3] ident: loosen getpwuid error in non-strict mode

From
Jeff King <peff@peff.net>
Date
Dec 14, 2015, 15:07 UTC
Message-ID
<20151214150729.GA21415@sigill.intra.peff.net>
In-Reply-To
<20151210214129.GC8374@sigill.intra.peff.net>
On Thu, Dec 10, 2015 at 04:41:29PM -0500, Jeff King wrote:
Show 21 quoted lines
> -static struct passwd *xgetpwuid_self(void)
> +static struct passwd *xgetpwuid_self(int *is_bogus)
>  {
>  	struct passwd *pw;
>  
>  	errno = 0;
>  	pw = getpwuid(getuid());
> -	if (!pw)
> -		die(_("unable to look up current user in the passwd file: %s"),
> -		    errno ? strerror(errno) : _("no such user"));
> +	if (!pw) {
> +		struct passwd fallback;
> +		fallback.pw_name = "unknown";
> +#ifndef NO_GECOS_IN_PWENT
> +		fallback.pw_gecos = "Unknown";
> +#endif
> +		pw = &fallback;
> +		if (is_bogus)
> +			*is_bogus = 1;
> +	}
>  	return pw;

Ugh. The fallback struct should be static, of course, as we are returning its address from the function.

Anybody have a brown paper bag I can borrow?
diff --git a/ident.c b/ident.c
index 74de079..831072c 100644
--- a/ident.c
+++ b/ident.c
@@ -32,7 +32,7 @@ static struct passwd *xgetpwuid_self(int *is_bogus)
 	errno = 0;
 	pw = getpwuid(getuid());
 	if (!pw) {
-		struct passwd fallback;
+		static struct passwd fallback;
 		fallback.pw_name = "unknown";
 #ifndef NO_GECOS_IN_PWENT
 		fallback.pw_gecos = "Unknown";

-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 16 of 20 in “git-clone fails when current user is not in /etc/passwd”
  1. Taylor Braun-JonesDec 2, 2015
  2. Taylor Braun-JonesDec 9, 2015
  3. Duy NguyenDec 9, 2015
  4. Duy NguyenDec 9, 2015
  5. Taylor Braun-JonesDec 9, 2015
  6. Taylor Braun-JonesDec 10, 2015
  7. Jeff KingDec 10, 2015
  8. Junio C HamanoDec 10, 2015
  9. Jeff KingDec 10, 2015
  10. 0/3 git-clone fails when current user is not in /etc/passwdJeff King, Dec 10, 2015
  11. 1/3 ident: make xgetpwuid_self() a static local helperJeff King, Dec 10, 2015
  12. Junio C HamanoDec 10, 2015
  13. 2/3 ident: keep a flag for bogus default_emailJeff King, Dec 10, 2015
  14. Jeff KingDec 10, 2015
  15. 3/3 ident: loosen getpwuid error in non-strict modeJeff King, Dec 10, 2015
  16. Jeff KingDec 14, 2015
  17. Junio C HamanoDec 10, 2015
  18. Taylor Braun-JonesDec 11, 2015
  19. Junio C HamanoDec 10, 2015
  20. Taylor Braun-JonesDec 10, 2015

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.