Skip to content

Commit

Permalink
ECLEVEL check has been improved.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukuchi committed Aug 29, 2020
1 parent f63b5e6 commit 5d7edae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions qrencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ STATIC_IN_RELEASE QRcode *QRcode_encodeMask(QRinput *input, int mask)
errno = EINVAL;
return NULL;
}
if(input->level > QR_ECLEVEL_H) {
if(!(input->level >= QR_ECLEVEL_L && input->level <= QR_ECLEVEL_H)) {
errno = EINVAL;
return NULL;
}
Expand Down Expand Up @@ -533,7 +533,7 @@ STATIC_IN_RELEASE QRcode *QRcode_encodeMaskMQR(QRinput *input, int mask)
errno = EINVAL;
return NULL;
}
if(input->level > QR_ECLEVEL_Q) {
if(!(input->level >= QR_ECLEVEL_L && input->level <= QR_ECLEVEL_Q)) {
errno = EINVAL;
return NULL;
}
Expand Down
40 changes: 39 additions & 1 deletion tests/test_qrencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,43 @@ static void test_oddBitCalcMQR(void)
testFinish();
}

static void test_invalid_inputMQR(void)
{
QRinput *input;
QRcode *code;

testStart("Testing invalid input (MQR).");
input = QRinput_newMQR(1, QR_ECLEVEL_L);
QRinput_append(input, QR_MODE_AN, 5, (unsigned char *)"TEST1");
input->version = -1;
input->level = QR_ECLEVEL_L;
code = QRcode_encodeInput(input);
assert_null(code, "invalid version(-1) was not checked.\n");
if(code != NULL) QRcode_free(code);

input->version = 5;
input->level = QR_ECLEVEL_L;
code = QRcode_encodeInput(input);
assert_null(code, "invalid version(5) access was not checked.\n");
if(code != NULL) QRcode_free(code);

input->version = 1;
input->level = (QRecLevel)(QR_ECLEVEL_H);
code = QRcode_encodeInput(input);
assert_null(code, "invalid level(H) access was not checked.\n");
if(code != NULL) QRcode_free(code);

input->version = 1;
input->level = (QRecLevel)-1;
code = QRcode_encodeInput(input);
assert_null(code, "invalid level(-1) access was not checked.\n");
if(code != NULL) QRcode_free(code);

QRinput_free(input);

testFinish();
}

static void test_mqrencode(void)
{
char *str = "MICROQR";
Expand Down Expand Up @@ -977,7 +1014,7 @@ static void test_apiversion(void)

int main(int argc, char **argv)
{
int tests = 32;
int tests = 33;
testInit(tests);
test_iterate();
test_iterate2();
Expand Down Expand Up @@ -1009,6 +1046,7 @@ int main(int argc, char **argv)
test_encodeTooLongMQR();
test_decodeShortMQR();
test_oddBitCalcMQR();
test_invalid_inputMQR();
test_mqrencode();
test_apiversion();
testReport(tests);
Expand Down

0 comments on commit 5d7edae

Please sign in to comment.