client: Use fnameat() to construct history file name

We truncate the user's home directory name to 1000 characters when
constructing the history file name.  Use fnameat() to fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2015-12-13 08:34:26 +01:00
parent 6b72fefafb
commit a0220e864f
3 changed files with 11 additions and 12 deletions

View file

@ -314,7 +314,7 @@ info.html/%.html: info/%.t
$(server): $(filter src/server/% src/lib/commands/% src/lib/player/% src/lib/subs/% src/lib/update/%, $(obj)) $(empth_obj) $(empth_lib) $(libs) $(server): $(filter src/server/% src/lib/commands/% src/lib/player/% src/lib/subs/% src/lib/update/%, $(obj)) $(empth_obj) $(empth_lib) $(libs)
$(call quiet-command,$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@,LINK $@) $(call quiet-command,$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@,LINK $@)
$(client): $(filter src/client/%, $(obj)) src/lib/global/version.o $(client): $(filter src/client/%, $(obj)) src/lib/global/version.o src/lib/gen/fnameat.o
$(call quiet-command,$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@,LINK $@) $(call quiet-command,$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@,LINK $@)
$(util): $(libs) $(util): $(libs)
@ -373,8 +373,9 @@ dist-client: $(cli_distgen)
$(tarball) $(TARNAME)-client-$(VERSION) \ $(tarball) $(TARNAME)-client-$(VERSION) \
-C $(srcdir)/src/client \ -C $(srcdir)/src/client \
$(notdir $(filter src/client/%, $(src)) $(cli_distgen)) \ $(notdir $(filter src/client/%, $(src)) $(cli_distgen)) \
-C $(srcdir)/include proto.h version.h \ -C $(srcdir)/include fnameat.h proto.h version.h \
-C $(srcdir)/src/lib/global version.c \ -C $(srcdir)/src/lib/global version.c \
-C $(srcdir)/src/lib/gen fnameat.c \
-C $(srcdir)/src/lib $(addprefix w32/, $(client/w32)) \ -C $(srcdir)/src/lib $(addprefix w32/, $(client/w32)) \
-C $(srcdir)/man empire.6 \ -C $(srcdir)/man empire.6 \
-C $(srcdir)/build-aux install-sh \ -C $(srcdir)/build-aux install-sh \

View file

@ -28,7 +28,7 @@
# Makefile.in: Makefile template for configure # Makefile.in: Makefile template for configure
# #
# Known contributors to this file: # Known contributors to this file:
# Markus Armbruster, 2005-2013 # Markus Armbruster, 2005-2015
# #
CC = @CC@ CC = @CC@
@ -53,8 +53,9 @@ srcdir = @srcdir@
VPATH = @srcdir@ VPATH = @srcdir@
prog = empire$E prog = empire$E
obj = expect.$O host.$O ipglob.$O linebuf.$O login.$O main.$O play.$O \ obj = expect.$O fnameat.$O host.$O ipglob.$O linebuf.$O login.$O \
ringbuf.$O secure.$O servcmd.$O termlib.$O version.$O $(LIBOBJS) main.$O play.$O ringbuf.$O secure.$O servcmd.$O termlib.$O version.$O \
$(LIBOBJS)
all: $(prog) all: $(prog)
@ -83,7 +84,7 @@ expect.$O: misc.h proto.h
host.$O: misc.h host.$O: misc.h
linebuf.$O: linebuf.h linebuf.$O: linebuf.h
login.$O: misc.h proto.h login.$O: misc.h proto.h
main.$O: misc.h version.h main.$O: fnameat.h misc.h version.h
play.$O: linebuf.h misc.h proto.h ringbuf.h secure.h play.$O: linebuf.h misc.h proto.h ringbuf.h secure.h
ringbuf.$O: ringbuf.h ringbuf.$O: ringbuf.h
secure.$O: ringbuf.h secure.h secure.$O: ringbuf.h secure.h

View file

@ -47,6 +47,7 @@
#include <pwd.h> #include <pwd.h>
#endif #endif
#include <unistd.h> #include <unistd.h>
#include "fnameat.h"
#include "misc.h" #include "misc.h"
#include "version.h" #include "version.h"
@ -190,12 +191,8 @@ main(int argc, char **argv)
sock = tcp_connect(host, port); sock = tcp_connect(host, port);
if (use_history_file) { if (use_history_file)
/* FIXME don't truncate udir */ history_file = fnameat(".empire_history", udir);
history_file = malloc(1024);
strncpy(history_file, udir, 1000);
strcat(history_file, "/.empire.history");
}
if (!login(sock, uname, country, passwd, send_kill, utf8)) if (!login(sock, uname, country, passwd, send_kill, utf8))
exit(1); exit(1);