Skip to content

Commit

Permalink
if QCBOR is not compiled with consistent -DCONFIG options, resulting …
Browse files Browse the repository at this point in the history
…in item.label being in different place

for plutoctrl_cbor.c than for compiled QCBOR library in libwhack.
  • Loading branch information
mcr committed Feb 19, 2021
1 parent 9e48a48 commit 8a29f67
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/whack.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ enum whack_CBOR_actions {
WHACK_INITIATE_OPPO=8,
WHACK_TERMINATE=9,
WHACK_ADD_KEY =10,
WHACK_NOOP =23,
};

#define CborSignatureTag 55799
Expand Down
2 changes: 2 additions & 0 deletions lib/libpluto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ CFLAGS+=-DLEAK_DETECTIVE

# for access to qcbor code, submodule of libwhack
CFLAGS+=-I${OPENSWANSRCDIR}/lib/libwhack/qcbor/inc
CFLAGS+= -DQCBOR_DISABLE_FLOAT_HW_USE
CFLAGS+= -DQCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA

ONEFILE=pluto_constants.c
SRCS=defs.c db_ops.c db2_ops.c ai2db.c spdb_print.c
Expand Down
4 changes: 3 additions & 1 deletion lib/libpluto/plutoctrl_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,10 @@ err_t whack_cbor_decode_msg(struct whack_message *wm, unsigned char *buf, size_t
if(item.uLabelType != QCBOR_TYPE_INT64) {
return "map key must be integer";
}
CBOR_DEBUG("%u found map with labeled: %ld\n", elemCount, item.label.int64);
CBOR_DEBUG("%u found map %d with labeled: %ld\n", elemCount, item.uDataType, item.label.int64);
switch(item.label.int64) {
case WHACK_NOOP:
break;
case WHACK_STATUS:
wm->whack_status = TRUE;
/* consume value, which is probably empty map */
Expand Down
2 changes: 1 addition & 1 deletion lib/libwhack/qcbor
10 changes: 10 additions & 0 deletions lib/libwhack/whackwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,21 +298,28 @@ err_t whack_cbor_encode_msg(struct whack_message *wm, unsigned char *buf, size_t
QCBOREncode_OpenMapInMapN(&qec, WHACK_ROUTE);
if(wm->name) {
QCBOREncode_AddSZStringToMapN(&qec, WHACK_OPT_NAME, wm->name);
} else {
QCBOREncode_AddInt64ToMapN(&qec, 0, 1);
}

QCBOREncode_CloseMap(&qec);
}

if(wm->whack_unroute) {
QCBOREncode_OpenMapInMapN(&qec, WHACK_UNROUTE);
if(wm->name) {
QCBOREncode_AddSZStringToMapN(&qec, WHACK_OPT_NAME, wm->name);
} else {
QCBOREncode_AddInt64ToMapN(&qec, 0, 1);
}
QCBOREncode_CloseMap(&qec);
}
if(wm->whack_initiate) {
QCBOREncode_OpenMapInMapN(&qec, WHACK_INITIATE);
if(wm->name) {
QCBOREncode_AddSZStringToMapN(&qec, WHACK_OPT_NAME, wm->name);
} else {
QCBOREncode_AddInt64ToMapN(&qec, 0, 1);
}
QCBOREncode_CloseMap(&qec);
}
Expand All @@ -327,6 +334,8 @@ err_t whack_cbor_encode_msg(struct whack_message *wm, unsigned char *buf, size_t
QCBOREncode_OpenMapInMapN(&qec, WHACK_TERMINATE);
if(wm->name) {
QCBOREncode_AddSZStringToMapN(&qec, WHACK_OPT_NAME, wm->name);
} else {
QCBOREncode_AddInt64ToMapN(&qec, 0, 1);
}
QCBOREncode_CloseMap(&qec);
}
Expand Down Expand Up @@ -362,6 +371,7 @@ err_t whack_cbor_encode_msg(struct whack_message *wm, unsigned char *buf, size_t
QCBOREncode_CloseMap(&qec);
}

//QCBOREncode_AddInt64ToMapN(&qec, WHACK_NOOP, 1);
QCBOREncode_CloseMap(&qec);

/* close the array */
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/libwhack/wo01-msgstop/msgstop.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ int main(int argc, char *argv[])
fwrite(wm_buf, outsize, 1, omsg);
fclose(omsg);

/* now decode it again */
memset(&wm1, 0, sizeof(wm1));
err = whack_cbor_decode_msg(&wm1, wm_buf, &outsize);
if(err) { printf("decode error: %s\n", err); exit(6); }

passert(wm1.whack_shutdown == TRUE);

report_leaks();

tool_close_log();
Expand Down

0 comments on commit 8a29f67

Please sign in to comment.