Commit graph

117 commits

Author SHA1 Message Date
Umherirrender
e9e784a09e build: Enable phan-taint-check-plugin and suppress issues
Taint check checks for possible security issues by tracking html
escaping and more by using phan.
This slows done the phan-job a bit and requires more ram

Keep the DoubleEscaped issues out to make reviewer easier

Adds suppression for false positives
Adds taint-annotation to help taint-check
Removes suppression for code phan now understand better by the tracking
of keys in taint-check
Fix some small issues by adding int cast or htmlspecialchars calls

Bug: T216348
Bug: T268920
Change-Id: I849ac4f120fd15b483e8939d4db45c98dc351259
2020-12-30 19:02:22 +01:00
Umherirrender
a36eca22b5 Improve code around internal queries in sqlite database class
Use database quote function for the internal table names
Rename variable to avoid reuse and not confuse taint

This makes taint happy

Bug: T216348
Change-Id: Ic35f63857e85cc523d655aad18384d5bfbc48420
2020-12-03 19:30:11 +00:00
Umherirrender
88fe512c22 Pass function name to database functions (rdbms/installer)
Change-Id: Ia37d37f2471960c1d9d04fd9bd86224058e88413
2020-06-07 21:06:47 +02:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
Reedy
98a2ef8608 Fix more Squiz.Scope.MethodScope.Missing
Change-Id: I271362623760be8d3aa3cffa84026e72c5d1b52a
2020-05-18 20:42:42 +00:00
Aaron Schulz
27cf5ace45 rdbms: add IDatabase::QUERY_* flags to obviate isWriteQuery()
This reduces regex overhead and reliance on brittle assumptions.
This will also be useful for complex write queries involving WITH.
Some RDBMS types allow writes with in the WITH aliases themselves,
in addition to the main query itself. Checking raw SQL strings for
such things would get fairly complex.

Change-Id: I8ac4bc4d671abf02f97e82c5daf7b21271b85e5e
2020-04-28 00:49:11 +00:00
Aaron Schulz
cbc700e186 rbms: optimize and rename truncateTable() to truncate()
Allow truncation of multiple tables. This also provides for
a way to avoid risky keywords like CASCADE for Postgres.

For Postgres, use RESTART IDENTITY, which has been supported
since Postgres 8.4.

Avoid TRUNCATE/DELETE queries for empty temp tables, which is
useful for integrations tests that frequently call this method.

Reorganize and tweak the regexes in Database::getTempWrites().
It now recognizes multi-table DROP/TRUNCATE (Postgres-style).

Change-Id: Idd49f118b20ea5a0f7a3e8c00369aabcd45dd44e
2020-04-21 01:26:18 -07:00
Aaron Schulz
303ec64395 rdbms: convert "Exception" try/catch blocks to "Throwable" or "RuntimeException"
Change-Id: I95c204c5c436c3504dcab9e7fe2ae27936ffb590
2020-04-02 01:14:17 +00:00
jenkins-bot
20a0c8ab5a Merge "rdbms: add QUERY_IGNORE_DBO_TRX to duplicateTableStructure() queries" 2020-03-29 16:42:34 +00:00
Aaron Schulz
d42ad1e215 rdbms: add QUERY_IGNORE_DBO_TRX to duplicateTableStructure() queries
Make related DatabaseSqlite::listTables() method directly use query()
rather than high-level wrapper.

Change-Id: I253f83091fb62fd0a449ac78d8846fb69bb808f6
2020-03-27 01:40:24 +00:00
Aaron Schulz
e1a8c4e2a0 rdbms: add IMaintainableDatabase::truncateTable()
Use it in MediaWikiIntegrationTestCase for resetting tables.

Also create Database::resetSequencesForTable() helper method from
the resetSequenceForTable() methods in the SQLite/Postgres classes.

Change-Id: I20945e20590e69340b1ce75f6bb2f6972375b00c
2020-03-25 01:36:06 +00:00
Aaron Schulz
935e81952b rdbms: set temp_store = "MEMORY" for SQLite by default for non-CLI mode
The use of TEMPORARY tables during web requests should be lightweight
enough to not require disk (e.g. for very large amounts of data).

Change-Id: Ib5fb065d4291d693c22f88998d5950b99c39f8b4
2020-03-19 21:58:20 -07:00
Aaron Schulz
13b11a946e rdbms: reduce duplication in Database via helper methods
Add several new internal methods to help with wrangling
the various formats that rows, conditions, options, and
unique key lists can come in. Remove now unused method
isMultiRowArray().

Add various sanity checks and logging for parameters to
upsert(), replace(), insert(), and insertSelect().

Move DatabasePostgresTest to the integration/ directory.

Change-Id: If5988a6f0816e8da2cbf2fd612e1a3e3a2e9c52f
2020-03-10 22:26:04 +00:00
Aaron Schulz
6cf729838f rdbms: remove pre-3.7.11 SQLite support given that the minimum is 3.8
Change-Id: I6699cc2c22f1088a42bb554981863cb0c0c47d3a
2020-03-04 13:44:08 -08:00
Thiemo Kreuz
6b2c9deef5 Replace all new stdClass() with identical (object)[]
This should be the exact same. Its more a style change than anything.
So why do it then?
* I believe this is much less confusing than code mentioning a weird
"standard class". Barely anybody knows what this is, and what the
difference between "object" and "stdClass" is.
* The code is shorter.
* It's even faster. In my micro benchmark it's twice as fast.

Change-Id: I7ee0e8ae6d9264a89b6cd1dd861f0466ae620ccc
2020-03-04 21:18:30 +00:00
Aaron Schulz
ccebc2317b rdbms: improve IDatabase method documentation and parameter names
Change-Id: I87c0c6e418fe19bd837b38ebdfb967466f967fca
2020-03-02 22:59:12 +00:00
Aaron Schulz
a14a1f39a1 rdbms: support native batched replace() in DatabaseSqlite
Change-Id: Icc6d6ff7412d6a686b200e7d8432840b46377d10
2020-03-02 15:10:15 +00:00
Aaron Schulz
5afaaa7481 rdbms: extend PRAGMA support in DatabaseSqlite to include "temp_store"
Change-Id: I5c03b618de1db15aadfdbc1ccde671e2f28612a2
2020-02-26 01:53:54 -08:00
Aaron Schulz
314efebb56 rdbms: add GREATEST/LEAST wrappers to IDatabase
Change-Id: I9de931123b03ce10713a3a9bbb34e1332dd5965b
2020-01-17 22:19:08 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
jenkins-bot
4cca28d8f6 Merge "rdbms: support native batched insert() in DatabaseSqlite" 2020-01-10 03:36:28 +00:00
Aaron Schulz
3c1c9b5098 rdbms: support native batched insert() in DatabaseSqlite
This was added in 4bd1b4b455 but reverted due to a bug in other
changes within that patch, namely, the replace() method changes.

Change-Id: Id73c3fed9e1862daeeecbf47bcfa53d1719c59bb
2020-01-06 18:17:46 +00:00
Umherirrender
9fdeaeab72 Migrate Database::query with true to IDatabase::QUERY_SILENCE_ERRORS
true is b/c for 1.32 query() argument

Change-Id: If221b0731276c5a8627327ed124d947d32ebd3fa
2019-12-30 22:33:50 +01:00
Umherirrender
665f73b9c5 Allow float for IDatabase::addQuotes
Change-Id: Ib8f16bb447fad8a07735d799d22049b236b96a20
2019-12-28 20:56:29 +01:00
jenkins-bot
793632f60c Merge "rdbms: rename fixIgnore() and declare method visibilities in DatabaseSqlite" 2019-11-22 23:55:01 +00:00
jenkins-bot
ab9d80f7c2 Merge "rdbms: process cache the version in DatabaseSqlite" 2019-11-22 23:54:45 +00:00
Tim Starling
673d496f2d Have Database::addQuotes() pass through bare integers without quoting
Quotes started being added to integers in r4984 (August 2004). Before
that, is_numeric() was used to determine whether to add quotes, so
quotes were omitted from numeric strings, which is obviously wrong.

The idea here is to use the type of the variable to hint to the database
as to whether quotes are needed. The results are somewhat inconsistent,
since some callers do not convert numeric strings obtained from user
input to integers. That makes it a more conservative change. Callers can
opt out of unquoted integers by casting them to string.

The reason for doing this is that quoting integers turns out to be not
as harmless as originally assumed. We found a case of it confusing the
MariaDB query planner, causing inappropriate indexes to be used.

I also made addQuotes() consistently return a string, instead of
returning an integer for boolean values. This was already the case for
MySQL, but it seems like a good idea everywhere.

Bug: T238378
Change-Id: I70473280f542ee5ecd79e187f580807410fbd548
2019-11-18 11:40:28 +11:00
Aaron Schulz
7262bbb795 rdbms: rename fixIgnore() and declare method visibilities in DatabaseSqlite
Change-Id: I583375e51480549d2bf2272bf004651d463445c1
2019-11-08 12:12:44 -08:00
Aaron Schulz
11665a5e9a rdbms: process cache the version in DatabaseSqlite
Change-Id: Ieffb8f3d97c31cec4f88931bb5a0af7e4bc5e362
2019-11-08 12:10:17 -08:00
Aaron Schulz
fb621c26a3 rdbms: various cleanups to LoadBalancer::reallyOpenConnection()
Move the DBO_TRX init logic out of Database::__construct() and into
LoadBalancer since the later already handles setting and clearing this
flag based on transaction rounds starting and ending.

Add 'lazyMasterHandle', 'topologyRole', and 'topologicalMaster' parameters
to Database::factory() and inject them via LoadBalancer all at once in order
to avoid worrying about call order. Move some type casting code to
Database::__construct().

Add IDatabase::getTopologyRole()/getTopologicalMaster().

Use constants for getLBInfo()/setLBInfo() for better usage tracking and
typo resistance.

Change-Id: I437ce434326601e6ba36d9aedc55db396dfe4452
2019-10-11 11:35:02 -07:00
Daimona Eaytoy
69cadf44a9 Unsuppress PhanParamsTooMany
This is the last repo-wide suppressed issue. Hurrah.

Bug: T231636
Change-Id: I3dc939f115bea14848c9c40bc52a7601f86ca0a7
2019-10-10 12:44:08 -07:00
Aaron Schulz
450ea60c65 rdbms: clean up some DatabaseSqlite variables and break some lines
Change-Id: I3857b08ac86dbb5233210e33afdbdd9ef0a291fb
2019-10-08 21:20:11 +00:00
Aaron Schulz
0350220e99 rdbms: rename $a => $rows in IDatabase and add Database::isMultiRowArray()
Change-Id: Ie98754539d1e722cfad2c36c06862344bc103208
2019-10-08 11:36:33 -07:00
Anomie
be8ef0f2c3 Revert "rdbms: optimize insert(), replace(), and upsert() for sqlite when possible"
This reverts commit 4bd1b4b455.

Reason for revert: Incorrect syntax for SQLite "ON CONFLICT (...) DO UPDATE".

Bug: T234795
Change-Id: I987e6e7052368d5d9d0b6de9dd189edc4feaebe5
2019-10-08 16:51:37 +00:00
Aaron Schulz
4bd1b4b455 rdbms: optimize insert(), replace(), and upsert() for sqlite when possible
Change-Id: Ic884a4ce42a99333f5176f7b681f8a8bba15d2a1
2019-10-03 01:45:24 +00:00
Aaron Schulz
2f8be5ca9d rdbms: cleanup visibility of Database::makeSelectOptions()
Change-Id: I2e18dd3d450ceec9895d3143074743bc206a943d
2019-09-03 20:27:27 -07:00
Aaron Schulz
3d5faa10f4 rdbms: clean up use of ATTACH queries in DatabaseSqlite
Defer the queries until a connection exists. Only issue issue the
them for databases that are different than the currently opened file.
Also, make handleSessionLossPreconnect() aware of attached databases.

In LoadBalancer::reallyOpenConnection(), avoid having the "catch" block
appear like it returns a half-constructed Database.

Change-Id: I9f676bb72a1ab06f0eac5820dce28231741c283d
2019-09-01 21:55:45 +00:00
Aaron Schulz
ec9333b2b0 rdbms: remove unused $fulltextEnabled field from DatabaseSqlite
Change-Id: Idad680485f6cf6b521a0ea33c02d30e78d1d6b50
2019-08-26 12:16:51 -07:00
Urbanecm
6ded91313c Revert "rdbms: make LoadBalancer::reallyOpenConnection() handle setting DBO_TRX"
This reverts commit 45831e619c.

Reason for revert: Caused beta not work at all.

Bug: T231162
Change-Id: Icc5c1fa0dc01082a622641ad96c22c939cd56d48
2019-08-25 16:39:33 +00:00
Aaron Schulz
45831e619c rdbms: make LoadBalancer::reallyOpenConnection() handle setting DBO_TRX
Make LoadBalancer::reallyOpenConnection() handle initializing DBO_TRX
instead of Database::__construct().

Also:
* Avoid having the "catch" block appear like it returns a
  half-constructed Database.
* Use the variable name $conn instead of $db to be consistent
  throughout the class. Only send Database::__construct() parameters
  that it recognizes instead of mixing in setLBInfo() data.

Change-Id: Iffc3d1d0713051a164adb51a4c4ee12e4ac887c3
2019-08-24 20:06:17 +00:00
Aaron Schulz
2eb5bdbac6 rdbms: remove DatabaseSqlite::checkForEnabledSearch() in favor of explicit queries
Change-Id: I0f13b9f054d7732f0e9694ec75c415f91a36ede9
2019-08-07 18:47:36 -07:00
Aaron Schulz
a3a6dfed2e rdbms: allow automatic PDO creation of SQLite database files
Define missing DatabaseSqlite::doSelectDomain() method to handle attempts
to change the database, prefix, and/or schema.

Also add sanity check to serverIsReadOnly() to make sure open() was called

Change-Id: I72c25bf4dab5e01def3fb9472217e7637aede1d4
2019-08-07 01:05:35 +00:00
Aaron Schulz
f2b5cbb0bd rdbms: make DatabaseSqlite::open() also check DBO_DEFAULT
Change-Id: Ib21078dc9d4aa8cba6c5cb6c25868af328c1cab6
2019-07-28 12:38:29 -04:00
jenkins-bot
436f8eb32f Merge "rdbms: remove various deprecated methods" 2019-07-26 15:16:38 +00:00
Aaron Schulz
4c7e4575f5 rdbms: remove various deprecated methods
Change-Id: I5ae923065a08078225b7df080cb92edca799ebaf
2019-07-26 15:56:02 +01:00
Aaron Schulz
023c73f612 rdbms: normalize Database open() code and error handling
Mainly:
* Use oci_new_connect() for Oracle to avoid broken connection reuse
  similar to the PGSQL_CONNECT_FORCE_NEW flag in DatabasePostgres
* Set 'client_min_messages' unconditionally for PostgreSQL
* Factor out Database::getConnectExceptionAndLog() helper method
* Use the same style of query() calls in DatabaseOracle::open() as
  the other subclasses
* Make sure the Database driver handle field is null on failure
  instead of false for sanity

Also:
* Disallow changing of Database handle DBO_* flags after construction
  where it does not make sense to change them
* Do not mention DBO_* flags meant for non-config use in $wgDBservers
* Ignore DBO_PERSISTENT for SQLite if DBO_TRX is also set for sanity
* Remove $wgDBOracleDRCP variable to discourage careless automatic
  setting of DBO_PERSISTENT that breaks LoadBalancer assumptions

Change-Id: Iea948f7f872294ea8fc5d897fc10c9d29b7141d5
2019-07-26 15:24:28 +01:00
Aaron Schulz
6c973b23fe rdbms: set QUERY_IGNORE_DBO_TRX flag in more places in DatabaseSqlite
Change-Id: Id965d35a3feb331ded31ecb39f342ce23a061712
2019-07-15 03:56:27 +00:00
Aaron Schulz
28484682ae rdbms: cleanup DatabaseSqlite::lock() error handling
Consolidate more code, including error checks, in open() like with
the other Database subclasses.

Change-Id: I55acae55a219f66c7e45b3a06d76b1d8741a4159
2019-07-11 20:44:38 +00:00
Aaron Schulz
a830c14d0b rdbms: make implement IResultWrapper directly instead of via inheritence
Change-Id: If1b15c0c21d0ee336025fb99f47fc19ddf1d5435
2019-07-04 13:42:53 +00:00
Aaron Schulz
e0cf8b94bb rdbms: make DatabaseSqlite try harder to make named locks work
Also make unlock() calls to non-existing locks return false

Change-Id: I9f0cd63e85392d1fab1868638896492bbd8e6531
2019-07-03 10:42:31 +00:00