Commit Graph

530 Commits

Author SHA1 Message Date
Benedikt Reinartz
e2b722ed46 Adjust loop callback signatures
`GFunc` is `void (gpointer, gpointer)` and `GHFunc` is `void (gpointer, gpointer, gpointer)`,
so the respective callback functions should have the same signature.
2021-04-25 12:47:33 +02:00
Evan Miller
05bee0c69f Remove unnecessary _XOPEN_SOURCE
This was originally intended to expose strptime, which is no longer
(never?) used  by data.c
2021-04-16 13:04:40 -04:00
Evan Miller
ceb65d6ece Conditionally define _XOPEN_SOURCE
Fixes #298
2021-04-13 07:19:19 -04:00
Evan Miller
fe0175aa63 Migrate to g_memdup2 (#288)
With fakeglib and older versions of GLib, fall back to g_memdup with
a #define inside mdbprivate.h.

Fixes #287
2021-04-05 09:04:29 -04:00
Evan Miller
d8a81c49a3 Merge pull request #277 from mdbtools/access-2019
Support Access 2019
2021-03-24 09:28:00 -04:00
Ulrich Weber
970023c4e6 fix segfault in SQLGetTypeInfo due pyodbc
dont access pages in mdb_fetch_row when pdata is not initialized.

Happens when a client, e.g. pyodbc, queries for an unsupported type,
e.g. SQL_WVARCHAR, temp_table is empty and further access to it will crash.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff70fe3df in mdb_fetch_row (table=0xa74610) at data.c:467
467				rows = mdb_get_int16(

Backtrace:
0  0x00007ffff70fe3df in mdb_fetch_row (table=0xa74610) at data.c:467
1  0x00007ffff77f8746 in SQLFetch (hstmt=0xa70500) at odbc.c:1074
2  0x00007ffff7729b43 in SQLFetch () from /lib/x86_64-linux-gnu/libodbc.so.2
3  0x00007ffff778d545 in GetColumnSize (cnxn=0x7ffff77eb1f0, cnxn=0x7ffff77eb1f0, psize=0x7ffff77bde00, sqltype=-9) at src/cnxninfo.cpp:81
4  CnxnInfo_New (cnxn=0x7ffff77eb1f0) at src/cnxninfo.cpp:145

Signed-off-by: Ulrich Weber <ulrich.weber@gmail.com>
2021-03-24 13:09:48 +00:00
Evan Miller
8f1f080e3f Support Access 2019
Per #260 I am assuming that the internal version 6 refers to files
created with Access 2019. I can't find any documentation on this format,
so I am calling it ACE17. Testing welcome.
2021-03-23 15:56:39 -04:00
HenriHakonen
d8a0d279e4 Update write.c
This way fwrite returns length. mdb_crack_row takes size instead of end.
2021-03-23 17:17:35 +02:00
Evan Miller
735351d0cb Fix signed-unsigned comparison
Fixes #269
2021-03-15 17:32:47 -04:00
Evan Miller
ad8c80892b Fix compilation error 2021-03-07 14:36:07 -05:00
Evan Miller
46a65b9789 Fix warning when reading binary properties
Also fix some type-size issues in mdb_col_to_string.

See #262
2021-03-07 09:03:39 -05:00
James Woodcock
2be45a3a0b Implement MySQL relations for schema exports 2021-02-16 19:39:00 +00:00
James Woodcock
8bf8806d4f Implement a MySQL serial type for schema exports 2021-02-16 19:32:27 +00:00
Evan Miller
1bfce353d4 Move mdb_col_to_string warning 2021-02-15 21:25:53 -05:00
Evan Miller
e655cba907 Fix handling of numeric types in ODBC driver
Fixes #255 and supersedes #256
2021-02-15 19:50:15 -05:00
kalpha2
25c39f38d0 Update write.c
added table name and column number to fprintf when invalid data location detected in mdb_crack_row
2021-02-10 15:33:33 +00:00
James Woodcock
a980d73447 mdb-export: handle MySQL blobs (#250)
* Refactor code so BLOBs are always correctly exported

Previously, BLOBs weren't exported from mdb-export correctly if the
backend had MDB_SHEXP_BULK_INSERT set.

* Export MySQL BLOBs correctly

MySQL BLOBs should be in the form 0x[hex values] when inserting them
with the mysql command line tool.

* MySQL needs a BLOB to store exported MDB_OLE values

MDB_OLE size always comes out as 256 bytes, but varbinary(256) is insufficient
to hold all possible OLE data.
2021-02-03 14:48:56 -05:00
Evan Miller
763716ecc6 Fix unused function warning without iconv 2021-02-02 18:40:40 -05:00
Evan Miller
4e969425ac Add (fake) g_unichar_to_utf8 2021-01-22 07:45:47 -05:00
Evan Miller
da80fb3430 Make mdb_iconv_name_from_code_page static 2021-01-21 23:25:46 -05:00
Evan Miller
468502bc87 Terminate string 2021-01-21 23:16:33 -05:00
Evan Miller
0aa3aeee42 Simplify (fake) g_locale_to_utf8
Use mbstowcs and a manual UTF-8 conversion so we don't have to sniff
the locale and require iconv.
2021-01-21 23:08:55 -05:00
Evan Miller
f1eac042b5 Fix misuse of "%*s" in sprintf strings
%*s takes the output length, not the input length. The intended
specifier was %.*s in several places. Bug(s) introduced in
2bb31f05ee
2021-01-21 18:27:20 -05:00
Evan Miller
615b625d79 Let LC_COLLATE influence string-comparison operations
By default this will be set to the C locale, but set it to the user's
locale when string comparisons are performed from mdb-sql. Note that
this can be overridden with the LC_COLLATE environment variable.

We could infer the collation locale from the file itself, but this will
likely require a big ball of glue between the Windows locales and Unix
ones.
2021-01-19 21:24:31 -05:00
Evan Miller
9e85bc4153 Clean up backend export logic
* Differentiate character lengths from byte lengths (see #112)

* Use GNU-style indexed initializers for clarity

* Remove needs_quotes since it's not used anywhere
2021-01-19 18:03:10 -05:00
Evan Miller
8c91654426 Man page and usage updates
* MDBOPTS=no_memo is not used anywhere; mark deprecated and print a
  warning if enabled

* Mark MDBOPTS=use_index as experimental in the man pages

* MDBOPTS need to be colon separated

* Document new long forms of mdb-queries options
2021-01-19 16:27:36 -05:00
Evan Miller
0aa88f85d5 Support scale/precision with more column types 2021-01-19 15:55:57 -05:00
Evan Miller
aec667a033 Fix numeric scale/precision on Jet3 databases 2021-01-19 15:23:28 -05:00
Evan Miller
8fff5b0ac0 Merge pull request #239 from pedromorgan/apidocs_1
apidocs with doxygen
2021-01-16 11:49:12 -05:00
pedromorgan
da730d3696 apidocs with doxygen 2021-01-16 16:05:28 +00:00
Evan Miller
dd13e20456 More bounds checking 2021-01-15 08:08:51 -05:00
Evan Miller
89e2361582 Fix buffer overrun (oss-fuzz/28832+28807)
len_out was wrapping to a large number when bad input was encountered.
Ensure it's non-zero before proceeding with iconv.
2021-01-15 07:44:50 -05:00
Evan Miller
0e3a627ee6 Make command-line arguments locale-aware (#237)
GLib will automatically convert command line options to UTF-8 provided that setlocale(LC_TYPE, "") is called first, and the argument type is STRING (but not FILENAME). Update the CLI tools to take advantage of this behavior, and likewise implement it in fakeglib.

GLib does not automatically convert non-option arguments (i.e. everything remaining in argv after option processing), so manually call g_locale_to_utf8 on these arguments when they represent table names. This should fix the CLI tools when processing non-ASCII table names in non-UTF-8 locales. Also update fakeglib to implement a fast and loose version of g_locale_to_utf8, and factor out some of the code page => iconv name logic in iconv.c so it can be used in our fake g_locale_to_utf8. This adds a new symbol mdb_iconv_name_from_code_page that is not advertised in the main header file. I did not want to include mdbtools.h from fakeglib.c, but maybe that's not important.
2021-01-14 17:34:50 -05:00
Evan Miller
20842c642a mdb-schema: Exit with code 1 if the requested table is not found 2021-01-12 14:08:25 -05:00
Evan Miller
7893a948ce Fix infinite loop (See oss-fuzz/28789)
A loop is still possible with mutually referencing pages but eliminating
self-references should fix the major timeouts
2021-01-07 21:29:37 -05:00
Evan Miller
c0880f0e40 Fix potential realloc() memory leak reading OLE objects
See oss-fuzz/28791
2021-01-07 21:11:12 -05:00
Evan Miller
c31daeb2c4 Improved bounds and return value checking (oss-fuzz/29329) 2021-01-07 19:59:45 -05:00
Evan Miller
9b5e591905 Improved bounds checking (fixes oss-fuzz/29328) 2021-01-07 18:46:07 -05:00
Evan Miller
24a7fdab78 Restore 0.9.0 API backward compatibility of mdb_print_col and MDB_BINEXPORT_*
Other programs (e.g. gmdb2) use mdb_print_col, so restore the old enum
names and values. MDB_EXPORT_ESCAPE_INVISIBLE can be OR'ed into the
last argument to enable C-style escaping of text fields.
2020-12-30 10:28:49 -05:00
Evan Miller
d51a37a760 Remove mdb_find_row and row_size warnings
These aren't helpful or actionable, and may not actually indicate any
kind of problem, so remove them.
2020-12-29 15:21:22 -05:00
Evan Miller
6db8ed13a6 Remove zero-row checks #120
Improperly closed databases may set num_rows to zero. Allow reading
of these tables anyway.
2020-12-29 15:10:31 -05:00
Evan Miller
197c3dc35a use_index now requires libmswstr. See #215 and #226
Print a warning if use_index is turned on but libmswstr is not found.  I
suppose we could enable indexes only on JET3 databases, but I am not at
all confident in the JET3 index logic, as it seems to break on non-ASCII
input. So I'd rather just print this warning and require some
hoop-jumping.
2020-12-29 13:13:25 -05:00
Evan Miller
0ad6fb33f6 Merge pull request #222 from evanmiller/merge-108
Revise and merge in #108 (new --escape-invisible flag to mdb-export)
2020-12-29 12:50:04 -05:00
Evan Miller
aeee354405 Fix infinite loop exporting SQLite schema 2020-12-29 09:24:31 -05:00
Evan Miller
538711e450 Remove unnecessary casts 2020-12-28 22:30:20 -05:00
Evan Miller
c10232fdf1 Use fewer hard-coded sizes 2020-12-28 22:04:06 -05:00
Evan Miller
eb5e6348b7 Fix misleading indentation 2020-12-28 21:08:50 -05:00
Evan Miller
5705d595c8 Replace constant with sizeof() 2020-12-28 21:06:38 -05:00
Evan Miller
a0ebd91114 Fix potential stack corruption
A mal-formed catalog could overrun certain stack variables. Move the
variables to the heap and allocate them to hold the active bind size.
2020-12-28 21:02:17 -05:00
Evan Miller
2bb31f05ee Improve bounds checking
No particular crashes, but replace strcpy / strncpy with snprintf
and GLib functions wherever possible.
2020-12-28 20:12:39 -05:00