Skip to content

Fixes: possible buffer overrun on interval conversion. Catalog length handling #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions driver/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -3127,7 +3127,7 @@ static SQLRETURN check_catalog_name(esodbc_dbc_st *dbc, SQLWCHAR *name,
if (len < 0) {
catalog.cnt = wcslen(name);
} else {
catalog.cnt = (size_t)len;
catalog.cnt = ((size_t)len)/sizeof(SQLWCHAR);
}
if (! EQ_WSTR(&dbc->catalog, &catalog)) {
if (! dbc->catalog.cnt) {
Expand Down Expand Up @@ -3281,7 +3281,7 @@ SQLRETURN EsSQLSetConnectAttrW(
case SQL_ATTR_CURRENT_CATALOG:
INFOH(dbc, "setting current catalog to: `" LWPDL "`.",
/* string should be 0-term'd */
0 <= StringLength ? StringLength : SHRT_MAX,
0 <= StringLength ? StringLength/sizeof(SQLWCHAR) : SHRT_MAX,
(SQLWCHAR *)Value);
return check_catalog_name(dbc, (SQLWCHAR *)Value, StringLength);

Expand Down
6 changes: 5 additions & 1 deletion driver/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -4495,7 +4495,9 @@ static SQLRETURN c2sql_str2interval(esodbc_rec_st *arec, esodbc_rec_st *irec,
INFOH(stmt, "translation buffer too small (%zu < %lld), "
"allocation needed.", sizeof(wbuff)/sizeof(wbuff[0]),
(size_t)octet_len);
wptr = malloc(octet_len * sizeof(SQLWCHAR));
/* 0-term is most of the time not counted in input str and
* ascii_c2w() writes it -> always allocate space for it */
wptr = malloc((octet_len + 1) * sizeof(SQLWCHAR));
if (! wptr) {
ERRNH(stmt, "OOM for %lld x SQLWCHAR", octet_len);
RET_HDIAGS(stmt, SQL_STATE_HY001);
Expand All @@ -4514,6 +4516,8 @@ static SQLRETURN c2sql_str2interval(esodbc_rec_st *arec, esodbc_rec_st *irec,
}
/* should only happen on too short input string */
RET_HDIAGS(stmt, SQL_STATE_22018);
} else {
assert(ret <= octet_len + 1); /* no overrun */
}
wstr.str = wptr;
wstr.cnt = (size_t)octet_len;
Expand Down