| 114 | PRINTF_FMT(4,5); |
| 115 | |
| 116 | static struct io_plan *bad_req_fmt(struct io_conn *conn, |
| 117 | struct client *c, |
| 118 | const u8 *msg_in, |
| 119 | const char *fmt, ...) |
| 120 | { |
| 121 | va_list ap; |
| 122 | char *str; |
| 123 | |
| 124 | va_start(ap, fmt); |
| 125 | str = tal_vfmt(tmpctx, fmt, ap); |
| 126 | va_end(ap); |
| 127 | |
| 128 | /*~ If the client was actually lightningd, it's Game Over; we actually |
| 129 | * fail in this case, and it will too. */ |
| 130 | if (is_lightningd(c)) { |
| 131 | status_broken("%s", str); |
| 132 | master_badmsg(fromwire_peektype(msg_in), msg_in); |
| 133 | } |
| 134 | |
| 135 | /*~ Nobody should give us bad requests; it's a sign something is broken */ |
| 136 | status_broken("%s: %s", type_to_string(tmpctx, struct node_id, &c->id), str); |
| 137 | |
| 138 | /*~ Note the use of NULL as the ctx arg to towire_hsmstatus_: only |
| 139 | * use NULL as the allocation when we're about to immediately free it |
| 140 | * or hand it off with take(), as here. That makes it clear we don't |
| 141 | * expect it to linger, and in fact our memleak detection will |
| 142 | * complain if it does (unlike using the deliberately-transient |
| 143 | * tmpctx). */ |
| 144 | daemon_conn_send(status_conn, |
| 145 | take(towire_hsmstatus_client_bad_request(NULL, |
| 146 | &c->id, |
| 147 | str, |
| 148 | msg_in))); |
| 149 | |
| 150 | /*~ The way ccan/io works is that you return the "plan" for what to do |
| 151 | * next (eg. io_read). io_close() is special: it means to close the |
| 152 | * connection. */ |
| 153 | return io_close(conn); |
| 154 | } |
| 155 | |
| 156 | /* Convenience wrapper for when we simply can't parse. */ |
| 157 | static struct io_plan *bad_req(struct io_conn *conn, |
no test coverage detected