From: Martin Mares Date: Wed, 6 Sep 2017 20:49:27 +0000 (+0200) Subject: Server: Fixed handling of exceptions during packet constructions X-Git-Tag: v0.9~21 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=2e5a931dd18959b88675bccd844b0226ec1f1099;p=subauth.git Server: Fixed handling of exceptions during packet constructions We fell into two LibUCW traps at once :) First, fastbuf operations generate proper exceptions only when the fastbuf is tied to a resource pool of the current transaction by fb_tie(). Otherwise, they call plain die(). Second, fb-buf did not support bclose(), so it could not have been tied. LibUCW 6.5.5 fixes the second problem, so let us tie the fb-buf properly. --- diff --git a/server/subauthd.c b/server/subauthd.c index df6d5e8..bdfe295 100644 --- a/server/subauthd.c +++ b/server/subauthd.c @@ -58,22 +58,26 @@ static void socket_timeout_handler(struct main_timer *tm) static void try_send_reply(struct client *c) { - struct fastbuf fb; - fbbuf_init_write(&fb, packet_buffer, MAX_PACKET_SIZE); + int len; TRANS_TRY { + struct fastbuf fb; + fbbuf_init_write(&fb, packet_buffer, MAX_PACKET_SIZE); + fb_tie(&fb); json_write(c->json, &fb, c->reply); + len = fbbuf_count_written(&fb); } TRANS_CATCH(x) { msg(L_ERROR, "Unable to construct reply, it is probably too long"); - fbbuf_init_write(&fb, packet_buffer, MAX_PACKET_SIZE); - bputs(&fb, "{ \"error\": \"Reply too long\" }\n"); + struct fastbuf fb2; + fbbuf_init_write(&fb2, packet_buffer, MAX_PACKET_SIZE); + bputs(&fb2, "{ \"error\": \"Reply too long\" }\n"); + len = fbbuf_count_written(&fb2); } TRANS_END; - int len = fbbuf_count_written(&fb); DBG("Sending reply of %d bytes", len); if (send(c->socket.fd, packet_buffer, len, 0) < 0) {