Closed mettatu closed 3 years ago
Was the database also migrated from SQLite to PostgreSQL at some point either during the 8.0.1 to 9.0.0 migration or earlier?
Other things to check would be the character encoding of the database (which you can by running psql gvmd -c 'SHOW SERVER_ENCODING'
as the postgres user) and the locale used to run gvmd.
Yes, the database was migrated from SQLite when upgrading to 8.0.1 earlier this year. I can confirm that the problematic entries were written originally to the SQLite database.
Database encoding:
server_encoding
-----------------
UTF8
(1 row)
System locale for the process:
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
I can confirm that the problematic entries were written originally to the SQLite database.
Do you still have a backup of the SQLite database to tell if the entries were already invalid UTF-8 there or if the migration to PostgreSQL may have broken them?
Unfortunately the original SQLite3 database is already scrapped with the old VMs. I think you are right, something went south during that time.
I tried to reproduce with PostgreSQL but everything worked ok.
1) I dropped the original database and created a fresh empty postgresql with:
Greenbone Vulnerability Manager version 8.0.2 (DB revision 205)
2) I scanned the target and confirmed that the database is written with:
Subject: O=ADVUNI¸ü,OU=Storage,CN=XXX,CN=10.10.10.10
When checking with OpenSSL, everything is nicely escaped:
subject=/CN=10.10.10.10/CN=XXX/OU=Storage/O=ADVUNI\xB8\xFC
3) Database migrated successfully with:
Greenbone Vulnerability Manager 9.0.0
Manager DB revision 221
md main:MESSAGE:2019-12-12 11h02.43 utc:18082: Greenbone Vulnerability Manager version 9.0.0 (DB revision 221)
md main: INFO:2019-12-12 11h02.43 utc:18082: Migrating database.
md main: INFO:2019-12-12 11h02.43 utc:18082: Migrating to 206
md main: INFO:2019-12-12 11h02.43 utc:18082: Migrating to 207
md main: INFO:2019-12-12 11h02.43 utc:18082: Migrating to 208
md main: INFO:2019-12-12 11h02.47 utc:18082: Migrating to 209
md main: INFO:2019-12-12 11h02.47 utc:18082: Migrating to 210
md main: INFO:2019-12-12 11h02.47 utc:18082: Migrating to 211
md main: INFO:2019-12-12 11h02.47 utc:18082: Migrating to 212
md main: INFO:2019-12-12 11h02.47 utc:18082: Migrating to 213
md main: INFO:2019-12-12 11h02.48 utc:18082: Migrating to 214
md main: INFO:2019-12-12 11h02.48 utc:18082: Migrating to 215
md main: INFO:2019-12-12 11h02.48 utc:18082: Migrating to 216
md main: INFO:2019-12-12 11h02.48 utc:18082: Migrating to 217
md main: INFO:2019-12-12 11h02.48 utc:18082: Migrating to 218
md main: INFO:2019-12-12 11h02.48 utc:18082: Migrating to 219
md main: INFO:2019-12-12 11h02.48 utc:18082: Migrating to 220
md main: INFO:2019-12-12 11h02.48 utc:18082: Migrating to 221
Expected behavior
During upgrade from GVMD 8.0.2 to 9.0.0, the database migration would succeed from revision 205 to 221.
Actual behavior
An error "sql_exec_internal: PQexec failed: ERROR: invalid byte sequence for encoding "UTF8": 0xb8" was logged during upgrade from revision 213 to 214.
Steps to reproduce
GVM versions
gvm: gvmd 8.0.1 -> gvmd 9.0.0
Logfiles
Strace from the migration script:
I checked the database and found out that the entry contained characters that caused the migration script to fail:
I ended up removing the results with problematic characters (from results and public.report_host_details table) and the database migration worked. Certificate is also base64 encoded in the public.report_host_details, it also needs to be removed to make it work.