Skip to contentSkip to conversation

git-shell needs $(COMPAT_OBJS)

PATCH In review Johannes Sixt 4 participants 8 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-shell needs $(COMPAT_OBJS)

---
Discovered by an accidental NO_MMAP=1 in config.mak.

-- Hannes

 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
index c676d97..2be40eb 100644
@@ -1203,7 +1203,7 @@ git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 
-git-shell$X: compat/strlcpy.o abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o
+git-shell$X: abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o $(COMPAT_OBJS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^)
 
 $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
Signature · 1 line
1.5.6.3.443.g5f70e
#1 lore raw
Quoted 4 lines · Johannes Sixt

-git-shell$X: compat/strlcpy.o abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o
+git-shell$X: abspath.o ctype.o
exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o $(COMPAT_OBJS)

Unfortunately, that's only half the deal. If we compile with NO_PREAD=1, this needs read_in_full(), which is in write_or_die.o. I don't know how to fix this without insulting your good taste except for reverting the recent commits that touch this line...

-- Hannes

#2 lore raw
Quoted 8 lines · Johannes Sixt
Quoted 4 lines · Johannes Sixt

-git-shell$X: compat/strlcpy.o abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o
+git-shell$X: abspath.o ctype.o
exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o $(COMPAT_OBJS)

Unfortunately, that's only half the deal. If we compile with NO_PREAD=1, this needs read_in_full(),...

Well, if compat/* implementations use anything outside compat/ left and right, then all bets are off.

Why do we care about the size of git-shell so much in the first place anyway to begin with?

#3 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Johannes Sixt
Quoted 4 lines · Johannes Sixt

-git-shell$X: compat/strlcpy.o abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o
+git-shell$X: abspath.o ctype.o
exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o $(COMPAT_OBJS)

Unfortunately, that's only half the deal. If we compile with NO_PREAD=1, this needs read_in_full(),...

Quoted 2 lines

Well, if compat/* implementations use anything outside compat/ left and right, then all bets are off.

If compat/ layer tries to really be about "compatibility", they should not be using things like xmalloc() that call release_pack_meory() that is in sha1_file.c. From a quick glance, mingw.c, mmap.c, pread.c are major offenders, but others such as setenv.c seem to be carefully written.

Perhaps we should apply a variant of your patch to allow linking from compat/ routines to git-shell, so that people affected by the compat layer functions that call outside compat layer have incentive to fix them.

 Makefile |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
Makefile +7 -3
index 2b670d7..551bde9 100644
@@ -324,6 +324,7 @@ endif
 export PERL_PATH
 
 LIB_FILE=libgit.a
+COMPAT_LIB = compat/lib.a
 XDIFF_LIB=xdiff/lib.a
 
 LIB_H += archive.h
@@ -1203,8 +1204,11 @@ git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 
-git-shell$X: compat/strlcpy.o abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^)
+$(COMPAT_LIB): $(COMPAT_OBJS)
+	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(COMPAT_OBJS)
+
+git-shell$X: abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o $(COMPAT_LIB)
+	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(COMPAT_LIB)
 
 $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
 $(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
@@ -1402,7 +1406,7 @@ distclean: clean
 
 clean:
 	$(RM) *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
-		$(LIB_FILE) $(XDIFF_LIB)
+		$(LIB_FILE) $(XDIFF_LIB) $(COMPAT_LIB)
 	$(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
 	$(RM) $(TEST_PROGRAMS)
 	$(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope*
#4 lore raw
Quoted 3 lines · Junio C Hamano

Perhaps we should apply a variant of your patch to allow linking from compat/ routines to git-shell, so that people affected by the compat layer functions that call outside compat layer have incentive to fix them.

So the previous one will be queued in 'pu' as...

Link shell with compat layer functions

This in the short term will break on platforms that use compat implemenations that call outside compat layer, but that is exactly what we want. To give incentive to fix things for people who are affected and more importantly have environment to test their fixes.

and here is an example to fix pread for you, even I do not need it, though.

-- >8 --
Move read_in_full() and write_in_full() to wrapper.c

A few compat/* layer functions call these functions, but we would really want to keep them thin, without depending too much on the libgit proper.

---
 wrapper.c      |   38 ++++++++++++++++++++++++++++++++++++++
 write_or_die.c |   38 --------------------------------------
 2 files changed, 38 insertions(+), 38 deletions(-)
wrapper.c +38 -0
index 4e04f76..93562f0 100644
@@ -133,6 +133,44 @@ ssize_t xwrite(int fd, const void *buf, size_t len)
 	}
 }
 
+ssize_t read_in_full(int fd, void *buf, size_t count)
+{
+	char *p = buf;
+	ssize_t total = 0;
+
+	while (count > 0) {
+		ssize_t loaded = xread(fd, p, count);
+		if (loaded <= 0)
+			return total ? total : loaded;
+		count -= loaded;
+		p += loaded;
+		total += loaded;
+	}
+
+	return total;
+}
+
+ssize_t write_in_full(int fd, const void *buf, size_t count)
+{
+	const char *p = buf;
+	ssize_t total = 0;
+
+	while (count > 0) {
+		ssize_t written = xwrite(fd, p, count);
+		if (written < 0)
+			return -1;
+		if (!written) {
+			errno = ENOSPC;
+			return -1;
+		}
+		count -= written;
+		p += written;
+		total += written;
+	}
+
+	return total;
+}
+
 int xdup(int fd)
 {
 	int ret = dup(fd);
write_or_die.c +0 -38
index e4c8e22..4c29255 100644
@@ -45,44 +45,6 @@ void maybe_flush_or_die(FILE *f, const char *desc)
 	}
 }
 
-ssize_t read_in_full(int fd, void *buf, size_t count)
-{
-	char *p = buf;
-	ssize_t total = 0;
-
-	while (count > 0) {
-		ssize_t loaded = xread(fd, p, count);
-		if (loaded <= 0)
-			return total ? total : loaded;
-		count -= loaded;
-		p += loaded;
-		total += loaded;
-	}
-
-	return total;
-}
-
-ssize_t write_in_full(int fd, const void *buf, size_t count)
-{
-	const char *p = buf;
-	ssize_t total = 0;
-
-	while (count > 0) {
-		ssize_t written = xwrite(fd, p, count);
-		if (written < 0)
-			return -1;
-		if (!written) {
-			errno = ENOSPC;
-			return -1;
-		}
-		count -= written;
-		p += written;
-		total += written;
-	}
-
-	return total;
-}
-
 void fsync_or_die(int fd, const char *msg)
 {
 	if (fsync(fd) < 0) {
#5 lore raw
In reply to Junio C Hamano

Hi,

Quoted 2 lines · Junio C Hamano

Why do we care about the size of git-shell so much in the first place anyway to begin with?

It was not me who proposed it, but I guess it was for auditing purposes:
git-shell is often the only point of entry for certain untrusted ssh users, and the less code is linked, the less code has to be analyzed for reachability (and then for security holes).

Ciao,
Dscho

#6 lore raw
Quoted 9 lines · Johannes Schindelin
Quoted 2 lines · Junio C Hamano

Why do we care about the size of git-shell so much in the first place anyway to begin with?

It was not me who proposed it, but I guess it was for auditing purposes:
git-shell is often the only point of entry for certain untrusted ssh users, and the less code is linked, the less code has to be analyzed for reachability (and then for security holes).

That's a rather misguided approach, isn't it?

After all, the work requested by the end user will be handled by code in the main git executable by spawning a subprocess, and you are auditing the codepath that leads to the spawning anyway.

#7 lore raw
Quoted 5 lines · Junio C Hamano

That's a rather misguided approach, isn't it?

After all, the work requested by the end user will be handled by code in the main git executable by spawning a subprocess, and you are auditing the codepath that leads to the spawning anyway.

Hm, but then what's the purpose of having git-shell as a not-builtin?