canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.32k stars 926 forks source link

lxc database sql dump doesn't escape apostrophe #11205

Closed geaaru closed 1 year ago

geaaru commented 1 year ago

Required information

Issue description

Using a LXD profile where the description contains ' generate a broken SQL dump.

Steps to reproduce

  1. Create the lxd-socket profile with these data: https://github.com/MottainaiCI/lxd-compose-galaxy/blob/master/envs/common/profiles/lxd-socket.yml
  lxc profile show lxd-socket
config: {}
description: |
  Mount the host LXD socket to
  manage from the container the host LXD
  instance.

  If it's used an unprivileged container
  it's needed change socket permissions.

  NOTE: on snapd this path could be different.
  Use --render-env "lxd_socket_path=xxx" to
  override the profile.
devices:
  lxd-socket:
    path: /var/lib/lxd/unix.socket
    source: /var/lib/lxd/unix.socket
    type: disk
name: lxd-socket
  1. Run dump:
date=$(date +%Y%m%d%H%M%S)
export PREV_PV=5.7

lxd sql local .dump > /var/lib/lxd/funtoo-backups/lxd-${PREV_PV}-${date}.sql
lxd sql global .dump > /var/lib/lxd/funtoo-backups/lxd-${PREV_PV}-${date}-global.sql
  1. Restore a database:
    $# cd /var/lib/lxd/database/global/
    $# cat /var/lib/lxd/funtoo-backups/lxd-5.7-20221208105015-global.sql | sqlite3 db.bin
    Parse error near line 169: near "s": syntax error
    from the container the host LXD instance.  If it's used an unprivileged conta
                                      error here ---^
tomponline commented 1 year ago

Using sqlite3 source code for this:

https://github.com/sqlite/sqlite/blob/37d4ec86bfa78c31732132b7729b8ce0e47da891/ext/misc/dbdump.c#L38