sqlite: safely move pointer values through SQL.

This lands https://www.sqlite.org/src/timeline?c=d6a44b35 in
third_party/sqlite/src/ and
third_party/sqlite/patches/0013-Add-new-interfaces-sqlite3_bind_pointer-sqlite3_resu.patch
and re-generates third_party/sqlite/amalgamation/* using the script at
third_party/sqlite/google_generate_amalgamation.sh.

The CL also adds a layout test that verifies the patch works as intended.

BUG=742407

Change-Id: I2e1a457459cd2e975e6241b630e7b79c82545981
Reviewed-on: https://chromium-review.googlesource.com/572976
Reviewed-by: Chris Mumford <cmumford@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487275}
int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs,
                                               int fd,
                                               sqlite3_file* pFile,
                                               const char* zPath,
                                               int noLock,
                                               int flags) {
  unixFile *p = (unixFile *)pFile;
  const int eType = flags&0xFFFFFF00;  /* Type of file to open */
  const int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0);
  int rc;

  memset(p, 0, sizeof(unixFile));

  /* osStat() will not work in the sandbox, so findReusableFd() will always
  ** fail, so directly include the failure-case setup then initialize pUnused.
  */
  if( eType==SQLITE_OPEN_MAIN_DB ){
    p->pUnused = sqlite3_malloc(sizeof(*p->pUnused));
    if (!p->pUnused) {
      return SQLITE_NOMEM_BKPT;
    }
    p->pUnused->fd = fd;
    p->pUnused->flags = flags;
  }

  rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
  if( rc!=SQLITE_OK ){
    sqlite3_free(p->pUnused);
  }
  return rc;
}

int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs,
                                               int fd,
                                               sqlite3_file* pFile,
                                               const char* zPath,
                                               int noLock,
                                               int flags) {
  unixFile *p = (unixFile *)pFile;
  const int eType = flags&0xFFFFFF00;  /* Type of file to open */
  const int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0);
  int rc;

  memset(p, 0, sizeof(unixFile));

  /* osStat() will not work in the sandbox, so findReusableFd() will always
  ** fail, so directly include the failure-case setup then initialize pUnused.
  */
  if( eType==SQLITE_OPEN_MAIN_DB ){
    p->pUnused = sqlite3_malloc(sizeof(*p->pUnused));
    if (!p->pUnused) {
      return SQLITE_NOMEM_BKPT;
    }
    p->pUnused->fd = fd;
    p->pUnused->flags = flags;
  }

  rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
  if( rc!=SQLITE_OK ){
    sqlite3_free(p->pUnused);
  }
  return rc;
}
