Skip to content

Commit d2bafa7

Browse files
committed
Fix API initialisation to actually ignore invalid packets or passwords
1 parent c552db6 commit d2bafa7

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/edge_management.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
381381
/* we reuse the buffer already on the stack for all our strings */
382382
STRBUF_INIT(buf, udp_buf, N2N_SN_PKTBUF_SIZE);
383383

384-
mgmt_req_init2(req, buf, (char *)&cmdlinebuf);
384+
if (!mgmt_req_init2(req, buf, (char *)&cmdlinebuf)) {
385+
// if anything failed during init
386+
return;
387+
}
385388

386389
if(req->type == N2N_MGMT_SUB) {
387390
int handler;

src/management.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int mgmt_auth (mgmt_req_t *req, char *auth) {
210210
/*
211211
* Handle the common and shred parts of the mgmt_req_t initialisation
212212
*/
213-
void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
213+
bool mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
214214
char *typechar;
215215
char *options;
216216
char *flagstr;
@@ -226,7 +226,7 @@ void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
226226
if(!typechar) {
227227
/* should not happen */
228228
mgmt_error(req, buf, "notype");
229-
return;
229+
return false;
230230
}
231231
if(*typechar == 'r') {
232232
req->type=N2N_MGMT_READ;
@@ -236,20 +236,20 @@ void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
236236
req->type=N2N_MGMT_SUB;
237237
} else {
238238
mgmt_error(req, buf, "badtype");
239-
return;
239+
return false;
240240
}
241241

242242
/* Extract the tag to use in all reply packets */
243243
options = strtok(NULL, " \r\n");
244244
if(!options) {
245245
mgmt_error(req, buf, "nooptions");
246-
return;
246+
return false;
247247
}
248248

249249
req->argv0 = strtok(NULL, " \r\n");
250250
if(!req->argv0) {
251251
mgmt_error(req, buf, "nocmd");
252-
return;
252+
return false;
253253
}
254254

255255
/*
@@ -281,6 +281,8 @@ void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
281281

282282
if(!mgmt_auth(req, auth)) {
283283
mgmt_error(req, buf, "badauth");
284-
return;
284+
return false;
285285
}
286+
287+
return true;
286288
}

src/management.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ void mgmt_event_post2 (enum n2n_event_topic topic, int data0, void *data1, mgmt_
109109
void mgmt_help_row (mgmt_req_t *req, strbuf_t *buf, char *cmd, char *help);
110110
void mgmt_help_events_row (mgmt_req_t *req, strbuf_t *buf, mgmt_req_t *sub, char *cmd, char *help);
111111
int mgmt_auth (mgmt_req_t *req, char *auth);
112-
void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline);
112+
bool mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline);
113113

114114
#endif

src/sn_management.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
241241
// xx
242242
STRBUF_INIT(buf, udp_buf, N2N_SN_PKTBUF_SIZE);
243243

244-
mgmt_req_init2(req, buf, (char *)&cmdlinebuf);
244+
if (!mgmt_req_init2(req, buf, (char *)&cmdlinebuf)) {
245+
// if anything failed during init
246+
return;
247+
}
245248

246249
int handler;
247250
lookup_handler(handler, mgmt_handlers, req->argv0);

0 commit comments

Comments
 (0)