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

Re: [PATCH] quickfetch(): Prevent overflow of the rev-list command line

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 8, 2009, 17:22 UTC
Message-ID
<7vws6j6qed.fsf@alter.siamese.dyndns.org>
In-Reply-To
<200907081801.36901.johan@herland.net>
Johan Herland <johan@herland.net> writes:
> Maybe I need to do something to the close() call as well? What happens
> on close() after EPIPE?
You should be OK (you could try this).

-- >8 -- #include <stdio.h> #include <errno.h> #include <stdlib.h> #include <signal.h> #include <string.h>

int main(int ac, char **av)
{
	int pipefd[2];
	int child;
	if (pipe(pipefd) < 0) {
		fprintf(stderr, "pipe failed: %s\n", strerror(errno));
		exit(1);
	}
	child = fork();
	if (child < 0) {
		fprintf(stderr, "fork failed: %s\n", strerror(errno));
		exit(1);
	} else if (child == 0) {
		char buf[1024];
		ssize_t sz;
		/* the child reads from the parent but does not talk back */
		close(pipefd[1]);
		/* emulate reading a bit, then dying without cleaning up */
		sz = read(pipefd[0], buf, sizeof(buf));
		fprintf(stderr, "read %lu bytes, and will die\n",
			(unsigned long) sz);
		exit(1);
	} else {
		const char data[] = "abcdefg";
		size_t len = sizeof(data);
		size_t written = 0;
		/* the parent writes to the child but does not listen */
		close(pipefd[0]);
		/* we will rite to the pipe even after the child is gone */
		signal(SIGPIPE, SIG_IGN);
		/* write, write, write, ... */
		while (1) {
			ssize_t sz = write(pipefd[1], data, len);
			if (sz < 0) {
				/* error */
				fprintf(stderr,
					"write failed (%s) after writing"
					" %lu bytes\n",
					strerror(errno),
					(unsigned long) written);
				break;
			}
			written += sz;
		}
		errno = 0;
		if (close(pipefd[1]))
			fprintf(stderr, "close failed: %s\n", strerror(errno));
		else
			fprintf(stderr, "close ok\n");
	}
	exit(0);
}
Previous: Johan HerlandNext: Johan Herland
Message 6 of 28 in “msysgit git-submodule: "Unable to fetch in submodule path ..."”
  1. Peter KreftingJun 18, 2009
  2. Peter KreftingJun 22, 2009
  3. quickfetch(): Prevent overflow of the rev-list command lineJohan Herland, Jul 8, 2009
  4. Johannes SixtJul 8, 2009
  5. Johan HerlandJul 8, 2009
  6. Junio C HamanoJul 8, 2009
  7. Johan HerlandJul 9, 2009
  8. Alex RiesenJul 9, 2009
  9. Johannes SixtJul 9, 2009
  10. Johan HerlandJul 9, 2009
  11. Johannes SixtJul 9, 2009
  12. quickfetch(): Prevent overflow of the rev-list command lineJohan Herland, Jul 9, 2009
  13. Johannes SixtJul 9, 2009
  14. quickfetch(): Prevent overflow of the rev-list command lineJohan Herland, Jul 9, 2009
  15. Johannes SixtJul 9, 2009
  16. Jeff KingJul 9, 2009
  17. quickfetch(): Prevent overflow of the rev-list command lineJohan Herland, Jul 9, 2009
  18. Johannes SixtJul 9, 2009
  19. quickfetch(): Prevent overflow of the rev-list command lineJohan Herland, Jul 9, 2009
  20. Junio C HamanoJul 11, 2009
  21. Johan HerlandJul 11, 2009
  22. Johan HerlandJul 9, 2009
  23. Johannes SixtJul 9, 2009
  24. Johan HerlandJul 9, 2009
  25. Johannes SixtJul 9, 2009
  26. Alex RiesenJul 9, 2009
  27. Johan HerlandJul 9, 2009
  28. Alex RiesenJul 9, 2009

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.