Skip to content

Commit 0c030e3

Browse files
committed
fix CBOR request length estimation (#181)
Fix a c&p error that uses the wrong parameter sizes for estimating the length of a CBOR request. (cherry picked from commit 6e977cd)
1 parent 1826ff0 commit 0c030e3

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

driver/queries.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2966,13 +2966,13 @@ static SQLRETURN statement_len_cbor(esodbc_stmt_st *stmt, size_t *enc_len,
29662966
(*keys) ++;
29672967
}
29682968
/* "field_multi_value_leniency": true/false */
2969-
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_MODE) - 1);
2969+
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_MULTIVAL) - 1);
29702970
bodylen += CBOR_OBJ_BOOL_LEN;
29712971
/* "index_include_frozen": true/false */
2972-
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_MODE) - 1);
2972+
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_IDX_FROZEN) - 1);
29732973
bodylen += CBOR_OBJ_BOOL_LEN;
29742974
/* "time_zone": "-05:45" */
2975-
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_MODE) - 1);
2975+
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_TIMEZONE) - 1);
29762976
bodylen += cbor_str_obj_len(tz_param.cnt); /* lax len */
29772977
*keys += 3; /* field_m._val., idx._inc._frozen, time_zone */
29782978
}

test/test_queries.cc

+20
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ TEST_F(Queries, attach_error_non_sql) {
8989
ASSERT_EQ(HDRH(stmt)->diag.native_code, SRC_AID3);
9090
}
9191

92+
TEST_F(Queries, cbor_serialize_alloc_body) {
93+
const size_t bsz = 64;
94+
wchar_t buff[bsz];
95+
wstr_st select = WSTR_INIT("SELECT '");
96+
cstr_st body = {(SQLCHAR *)buff, /*same size as the Q: force realloc*/bsz};
97+
98+
/* construct a valid query, though irrelevant for the test a.t.p. */
99+
wmemset(buff, L'*', bsz);
100+
wmemcpy(buff, select.str, select.cnt);
101+
buff[bsz - 2] = L'\'';
102+
buff[bsz - 1] = L'\0';
103+
104+
DBCH(dbc)->pack_json = FALSE;
105+
ASSERT_TRUE(SQL_SUCCEEDED(attach_sql(STMH(stmt), (SQLWCHAR *)buff,
106+
bsz - 1)));
107+
ASSERT_TRUE(SQL_SUCCEEDED(serialize_statement(STMH(stmt), &body)));
108+
ASSERT_NE((void *)body.str, (void *)buff);
109+
free(body.str);
110+
}
111+
92112
TEST_F(Queries, SQLNativeSql) {
93113
#undef SRC_STR
94114
#define SRC_STR "SELECT 1"

0 commit comments

Comments
 (0)