After applying the select() and buffered-read patches,
the server at least answers the client, but quickly
segfaulted, presumably because of some mismatch between
client and server (could DEBUG cause that ? did not check).
Message before crash was a complaint about entity 10 not
existing.
I tracked this to entity_type() possibly returning NULL.
At least in server/entity.c::entity_new() this is not
checked, NULL is dereferenced a couple of lines later.
Any misbehaving client could cause this, this is bad.
Trapping the NULL here with the following only moves the
error one layer up, to a function not returning an error
code. Luckily for me, recompiling the whole and using
matching binaries appears not to trigger this condition.
--- xtux-0.2.000602.orig/src/server/entity.c
+++ xtux-0.2.000602/src/server/entity.c
@@ -339,6 +339,10 @@
/* Set values from default type for this particular entity */
et = entity_type(type);
+ if (et == NULL) {
+ free (ent);
+ return NULL;
+ }
ent->type = type;
ent->class = et->class;
ent->mode = ALIVE;