Browse Source

Fix silent failure of sizeof for STRBUF_INIT()

pull/1129/head
Hamish Coleman 1 year ago
parent
commit
0d005d189d
  1. 8
      src/edge_management.c
  2. 2
      src/management.c
  3. 2
      src/sn_management.c
  4. 6
      src/strbuf.h

8
src/edge_management.c

@ -381,7 +381,7 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
traceEvent(TRACE_DEBUG, "mgmt json %s", cmdlinebuf); traceEvent(TRACE_DEBUG, "mgmt json %s", cmdlinebuf);
/* we reuse the buffer already on the stack for all our strings */ /* we reuse the buffer already on the stack for all our strings */
STRBUF_INIT(buf, udp_buf); STRBUF_INIT(buf, udp_buf, N2N_SN_PKTBUF_SIZE);
mgmt_req_init2(req, buf, (char *)&cmdlinebuf); mgmt_req_init2(req, buf, (char *)&cmdlinebuf);
@ -476,7 +476,7 @@ void readFromMgmtSocket (n2n_edge_t *eee) {
if((0 == memcmp(udp_buf, "help", 4)) || (0 == memcmp(udp_buf, "?", 1))) { if((0 == memcmp(udp_buf, "help", 4)) || (0 == memcmp(udp_buf, "?", 1))) {
strbuf_t *buf; strbuf_t *buf;
STRBUF_INIT(buf, &udp_buf); STRBUF_INIT(buf, &udp_buf, sizeof(udp_buf));
msg_len = snprintf(buf->str, buf->size, msg_len = snprintf(buf->str, buf->size,
"Help for edge management console:\n" "Help for edge management console:\n"
"\tstop | Gracefully exit edge\n" "\tstop | Gracefully exit edge\n"
@ -505,7 +505,7 @@ void readFromMgmtSocket (n2n_edge_t *eee) {
traceEvent(TRACE_NORMAL, "+verb traceLevel=%u", (unsigned int) getTraceLevel()); traceEvent(TRACE_NORMAL, "+verb traceLevel=%u", (unsigned int) getTraceLevel());
strbuf_t *buf; strbuf_t *buf;
STRBUF_INIT(buf, &udp_buf); STRBUF_INIT(buf, &udp_buf, sizeof(udp_buf));
msg_len = snprintf(buf->str, buf->size, msg_len = snprintf(buf->str, buf->size,
"> +OK traceLevel=%u\n", (unsigned int) getTraceLevel()); "> +OK traceLevel=%u\n", (unsigned int) getTraceLevel());
@ -516,7 +516,7 @@ void readFromMgmtSocket (n2n_edge_t *eee) {
if(0 == memcmp(udp_buf, "-verb", 5)) { if(0 == memcmp(udp_buf, "-verb", 5)) {
strbuf_t *buf; strbuf_t *buf;
STRBUF_INIT(buf, &udp_buf); STRBUF_INIT(buf, &udp_buf, sizeof(udp_buf));
if(getTraceLevel() > 0) { if(getTraceLevel() > 0) {
setTraceLevel(getTraceLevel() - 1); setTraceLevel(getTraceLevel() - 1);

2
src/management.c

@ -102,7 +102,7 @@ void mgmt_event_post2 (enum n2n_event_topic topic, int data0, void *data1, mgmt_
char buf_space[100]; char buf_space[100];
strbuf_t *buf; strbuf_t *buf;
STRBUF_INIT(buf, buf_space); STRBUF_INIT(buf, buf_space, sizeof(buf_space));
char *tag; char *tag;
if(sub->type == N2N_MGMT_SUB) { if(sub->type == N2N_MGMT_SUB) {

2
src/sn_management.c

@ -240,7 +240,7 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
/* we reuse the buffer already on the stack for all our strings */ /* we reuse the buffer already on the stack for all our strings */
// xx // xx
STRBUF_INIT(buf, udp_buf); STRBUF_INIT(buf, udp_buf, N2N_SN_PKTBUF_SIZE);
mgmt_req_init2(req, buf, (char *)&cmdlinebuf); mgmt_req_init2(req, buf, (char *)&cmdlinebuf);

6
src/strbuf.h

@ -14,10 +14,10 @@ typedef struct strbuf {
} strbuf_t; } strbuf_t;
// Initialise the strbuf pointer buf to point at the storage area p // Initialise the strbuf pointer buf to point at the storage area p
// p must be a known sized object // of size buflen
#define STRBUF_INIT(buf,p) do { \ #define STRBUF_INIT(buf,p,buflen) do { \
buf = (void *)p; \ buf = (void *)p; \
buf->size = sizeof(*p) - sizeof(size_t); \ buf->size = buflen - sizeof(size_t); \
} while(0) } while(0)

Loading…
Cancel
Save