Commit Graph

830 Commits

Author SHA1 Message Date
Evan Miller
8dd10d332e Merge pull request #228 from evanmiller/no-math
Remove math.h
2020-12-21 15:34:16 -05:00
Evan Miller
25435201b4 Remove math.h 2020-12-21 11:26:45 -05:00
Evan Miller
3001c3b94f Use the language ID from the DB header for indexing
According to the HACKING file, the file's default language ID is stored
in the database header. Use this value instead of a generic English
language locale for indexing JET4 files.

Columns can have their own text sorting rules, including language ID
distinct from the file's language ID, but this is not addressed as we'd
have to break the mdb_index_hash_text function signature, which I'm not
prepared to do just yet.

There appear to be two bytes after the language ID that may indicate
additional sorting flags. These bytes need additional research.
2020-12-21 09:11:42 -05:00
Evan Miller
b8ec7a2ec7 Use GCC style initializers for MdbFormatConstants 2020-12-20 20:15:13 -05:00
Evan Miller
f85905b5c8 Add a simple Latin-1 => UTF-8 transcoder w/o iconv 2020-12-20 19:54:51 -05:00
Evan Miller
134306d1af Simplify header-reading logic and support JET3 code pages
Using the notes and RC4 key provided in the HACKING file, decrypt the
database definition page all at once instead of decrypting individual
fields with ad-hoc keys. Use the newly decrypted header to access the
database code page at offset 0x3C, and use this numeric value to
initialize the iconv converter with an appropriate charset name for
popular windows code pages. More encodings can be added later, with
the eventual goal of getting rid of the MDB_JET3_CHARSET environment
variable.

Note that individual columns can have their own code pages but this
issue is not addressed.

An extra field is added to the MdbFile structure - because this
struct is allocated internally, this should not break the public
ABI.

Finally, only set the db_passwd field if it's a JET3 database (see #144)
2020-12-20 18:02:23 -05:00
Evan Miller
a8414720e4 Use wcstombs when iconv is not present (#223)
Replace the jerry-built UTF-16 => Latin-1 code path with a cross-platform wcstombs solution that emits UTF-8.

This adds an element to the end of the MdbHandle struct, but should not break any existing code.

A run-time option could be added later to emit other encodings, but people who care about such things can just use the iconv code path.
2020-12-20 17:56:33 -05:00
Evan Miller
fb6637c503 Fix unused but set variable warning (#221)
Refactor mdb_unicode2ascii to eliminate warnings
2020-12-19 09:37:39 -05:00
Evan Miller
1b96ef4b0d Clarify mdb_unicode2ascii API and fix buffer overrun (#220)
There was some confusion as to whether the destination buffer length
should include space for the null terminator. Some callers of the
function assumed that a terminator would be added beyond the end
of the stated buffer size, while others did not. Make everything
consistent and also fix an overrun when there was insufficient
space for the output in the non-iconv implementation.

As stated in a code comment, a better solution would follow the lead
of libxls and use wcstombs and friends when iconv is not available.
But this gets into the weeds with conversion functions named differently
across platforms. The goal here is to fix the buffer overrun.

See oss-fuzz/28773
2020-12-19 08:24:32 -05:00
Evan Miller
7ce75142e8 Merge pull request #219 from evanmiller/oss-fuzz-28790
Fix integer overflow
2020-12-18 19:51:59 -05:00
Evan Miller
50c9bdfee6 Fix buffer overflow (#218)
See oss-fuzz/28787
2020-12-18 19:42:11 -05:00
Evan Miller
78bbf4250e Merge pull request #217 from evanmiller/oss-fuzz-28780
Fix stack overflow
2020-12-18 16:35:48 -05:00
Evan Miller
16d249748a Fix integer overflow
See oss-fuzz/28790
2020-12-18 11:22:52 -05:00
Evan Miller
89007cba18 Fix stack overflow
See oss-fuzz/28780
2020-12-18 09:35:12 -05:00
Evan Miller
a1cda27a58 Null-terminate binary strings
See oss-fuzz/28779
2020-12-18 09:26:28 -05:00
Evan Miller
e7d5125e2b Fix libmdbsql build on Windows 2020-12-17 11:04:54 -05:00
Evan Miller
cd7ced0da0 Remove mem.c from Makefile 2020-11-27 06:02:26 -05:00
Evan Miller
eb39a483a3 Remove long-deprecated functions
mdb_init() and mdb_exit() have done nothing for a while.

mdb_get_coltype_string() and mdb_coltype_takes_length() were previously
removed, but remained in the header file by accident.
2020-11-27 05:58:14 -05:00
Nirgal Vourgère
cc15473d71 Deprecate mdb-array mdb-header mdb-parsecsv 2020-11-25 12:14:45 +01:00
Evan Miller
1efe8fc709 Merge pull request #194 from evanmiller/bounds-check-mdb-sql-bind-column
[Updated] Bounds check mdb_sql_bind_column()
2020-11-14 08:16:53 -05:00
Evan Miller
5f55b259de Merge pull request #195 from evanmiller/thread-safety
Use re-entrant functions and thread-local storage in a couple of places
2020-11-12 16:14:15 -05:00
Evan Miller
df48fcb284 Use thread-local storage to cache run-time options 2020-11-12 13:38:32 -05:00
Evan Miller
1bef1b1dca Use re-entrant functions in a couple of places
Replace strtok and gmtime with their re-entrant versions. More to come.
2020-11-12 11:20:05 -05:00
Evan Miller
12de22459a Fix indentation warning on GCC 2020-11-08 09:39:59 -05:00
Evan Miller
cdc0d184f2 Fix syntax error 2020-11-08 09:25:26 -05:00
Evan Miller
514e0fded0 Merge pull request #185 from mjwoodcock/odbc-string-truncation
Don't include length of '\0' in SQLGetData pcbValue
2020-11-08 09:19:28 -05:00
Evan Miller
bbc53dfade Bounds check mdb_sql_bind_column()
Return -1 if the bounds check fails, otherwise the result of
mdb_bind_column_by_name.

Update other places in the code to check the return value.
2020-11-08 08:50:17 -05:00
Evan Miller
38ce7db045 Large file support on 32-bit systems
* Add AC_SYS_LARGEFILE to configure.ac

* Replace fseek with fseeko
2020-11-07 11:40:44 -05:00
Evan Miller
ad14a04dfa Merge pull request #192 from evanmiller/merge-166
Original author: @rogerswb 

* Dynamic allocation of MdbSQL->bound_values 

Was previously hardcoded to 256 columns max.
2020-11-01 08:31:50 -05:00
James Woodcock
42996dad65 Send error message to stderr 2020-11-01 12:56:38 +00:00
Evan Miller
8b7162ded3 Merge branch 'dev' of github.com:mdbtools/mdbtools into merge-166 2020-11-01 07:55:53 -05:00
James Woodcock
de4f5516b7 Handle errors from mdb_bind_column() 2020-10-31 09:46:00 +00:00
James Woodcock
50f1bd4a86 Return column number from mdb_bind_column()
To match the return from mdb_bind_column_by_name().
2020-10-31 09:40:24 +00:00
James Woodcock
2e8480d7e5 Merge branch 'dev' of https://github.com/mdbtools/mdbtools into bounds-check-mdb-bind-column 2020-10-31 09:38:03 +00:00
Nirgal Vourgère
9e50c7401d Modernize bash-completion
Use _init_completion
Support long options with or without =
Auto generate options from the --help using _parse_help
2020-10-27 00:05:26 +01:00
nirgal
58f240ac6f Added back -q support 2020-10-25 20:49:20 +00:00
Nirgal Vourgère
f6053aa211 Quote shell special characters ...
... and add support for mdb-count mdb-json and mdb-queries
2020-10-25 20:19:39 +01:00
Nirgal Vourgère
c7d527fdeb mdb-export: Rename --backend into --insert 2020-10-25 12:09:51 +01:00
Nirgal Vourgère
ea478f3bc6 mdb-export: reorder options, man, bash-completion 2020-10-25 11:24:28 +01:00
Rainer Hurling
5b292e0063 Unsigned error in index.c
On FreeBSD 13.0-CURRENT its compiler clang-11.0.0 complains:
index.c:388:14: error: comparison of integers of different signs: 'int' and 'unsigned int' [-Werror,-Wsign-compare]
                for (i=0; i<len+1; i++) {
                          ~^~~~~~
2020-10-24 20:29:46 +02:00
James Woodcock
a7885f2680 Bounds check mdb_bind_column()
Return -1 to report out of bounds column number.
2020-10-24 13:27:34 +01:00
James Woodcock
06868e58ae Don't include length of '\0' in SQLGetData pcbValue
SQLGetData() should return the length of the string without the
null terminator.
2020-10-24 09:47:10 +01:00
James Woodcock
9bf70e0e1e mdb-export: use sensible date formats 2020-10-24 09:41:39 +01:00
Nirgal Vourgère
d0d95f6503 Install bash-completion snippets by default
Added autoconf --with-bash-completion-dir and --without-bash-completion-dir options
2020-10-23 18:58:45 +02:00
Nirgal Vourgère
f192c258ab bash-completion: get rid of "have" calls
have function disappeared in bash-completion 1.90 (2011)
2020-10-23 14:05:50 +02:00
Evan Miller
131b443102 Do not exit from library 2020-10-18 09:45:51 -04:00
Evan Miller
d8ed91bb05 Include missing header files in make dist 2020-10-18 07:59:45 -04:00
nirgal
6a41020538 Spelling typo 2020-10-18 08:59:36 +00:00
Nyall Dawson
3ac497c6ff Fix crash when a missing file is accessed via ODBC 2020-10-12 13:47:11 +10:00
Evan Miller
a051350ba1 make distcheck fixes 2020-10-11 15:46:19 -04:00