You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the driver queries the data, for example with an integer type in the DB you may get 2147483647
it translates the data to its string value, so for our example "2147483647"
the library frontend takes this value and sets the COBOL data
... so far: totally correct.
The issue is that in all those places the local allocated buffer that is used to write the data to is allocated based on dlength - the length of the COBOL field, but the memcpy is based on the strlen(data), which can be bigger.
In the example above, given a COBOL definition of S9(8) we allocate 8 (+1 for strlen) bytes, but create_coboldata copies the 10 bytes from the data size (*ptr != '\0' / strlen()). In the case of OCDB_TYPE_SIGNED_NUMBER_TC:
This is related to the "in progress" issue #31 and should ideally be solved together with that.
Given the code in
Open-COBOL-ESQL/dblib/ocesql.c
Lines 2789 to 3172 in 1b272b8
... so far: totally correct.
The issue is that in all those places the local allocated buffer that is used to write the data to is allocated based on
dlength
- the length of the COBOL field, but thememcpy
is based on thestrlen(data)
, which can be bigger.In the example above, given a COBOL definition of
S9(8)
we allocate 8 (+1 for strlen) bytes, butcreate_coboldata
copies the 10 bytes from the data size (*ptr != '\0'
/strlen()
). In the case ofOCDB_TYPE_SIGNED_NUMBER_TC
:Open-COBOL-ESQL/dblib/ocesql.c
Lines 2867 to 2881 in 1b272b8
we compute
fillzero
which will end up with-2
and then copy the data "two bytes before the allocated buffer".If this does not crash the memory layout, then the end result looks correct (left-truncation).
As seen above the truncation must be explicit checked, both to return the correct values and even more important to don't trash the memory.
And very likely after the data is stored with COBOL correct truncation an sqlcode for "field truncated" should be set.
The text was updated successfully, but these errors were encountered: