SQLite User Forum

BUG? Android SQLite CLI Temp file location
Login

BUG? Android SQLite CLI Temp file location

(1) By DiamondJohn on 2022-10-05 09:47:41 [link] [source]

I think I have found a bug in the command line interface of SQLite3 running on an android device. I'm Running v3.39.3 I think it bugs out on a "CREATE TEMP TABLE XXX ....".

I have a script, dependent on a lot of things, so its hard to give a duplicate test case. I tried, but I could not duplicate the issue (outside of my specific case). However, the fact that it even tries to write to /data/local/ instead of /data/local/tmp is an issue (as shown in the error message)

The script is run from a non root shell from an android app (so its run from the cache path). I get the following error: /data/user/0/diam...snip...fi/cache/runner.sh[116]: can't create temporary file /data/local/sh2pql26.tmp: Permission denied

Its clearly creating temp files in /data/local/*

So, I tested in a non root shell, and get the same error

sunfish:/ $ touch /data/local/test.txt
touch: '/data/local/test.txt': Permission denied

Writes to /data/local/ FAILS as non root user

However, a non root user CAN write to /data/local/tmp. It WORKS as non root user.

sunfish:/ $ touch /data/local/tmp/test.txt
sunfish:/ $

Just to confirm the obvious, /data/local/ works as root user

sunfish:/ $ su
sunfish:/ # touch /data/local/test.txt
sunfish:/ # exit
sunfish:/ $

The environment variable for temp is also being ignored

sunfish:/ $ echo $TMPDIR
/data/local/tmp

So I think sqlite is ignoring the environment variable, and simply assuming the incorrect path of /data/local is writeable, by a non root user.

I think under android, it should first use the environment variable TMPDIR and then fall back to /data/local/tmp if not set

(2) By Dan Kennedy (dan) on 2022-10-05 11:17:48 in reply to 1 [link] [source]

Its clearly creating temp files in /data/local/*

Why is it doing that? That path is not hard-coded into SQLite. Is it the SQLITE_TMPDIR variable? Or is one of /var/tmp /usr/tmp or /tmp a link to /data/local/?

Dan.

(3) By Sunny Saini (SunnySaini_com) on 2022-10-06 04:07:57 in reply to 2 [link] [source]

I have rooted phone Lenovo K3 Note Android 5.1 Lollipop.

Folder /var/ isn't available.

I couldn't find any temporary file in folder /data/local/ as well as /data/local/tmp when I created a temp table and filled some records in the temp table.

App used is aSQLiteManager.

(4) By DiamondJohn on 2022-10-06 06:57:16 in reply to 3 [link] [source]

This effect is specific to the CLI and specific to running NON ROOTED. The error does not occur when running as root, as root user does have permissions to /data/local/

(6) By DiamondJohn on 2022-10-06 07:10:11 in reply to 3 [link] [source]

If it fails, then you will not see the file. I also have found it difficult to repeat the situation outside of my app; which had a large database (>100MB in trying to test the limits/border conditions)

(5) By DiamondJohn on 2022-10-06 07:08:18 in reply to 2 [link] [source]

Its not a link, its a physical path.

I have not tested SQLITE_TMPDIR exported environment var. I'll give it a go and report back.

However, even if it works, it still should default to /data/local/tmp and not /data/local/

I dont know why it does, I was also hoping someone could confirm/repeat it. Trying to push it into a state where it requires the use of temporary files is not easy. I tried to duplicate it in a standalone script I could post as an example, and failed.

(7.1) By DiamondJohn on 2022-10-07 07:01:52 edited from 7.0 in reply to 2 [source]

Tried the following and it still appears to try and create temp files in /data/local

Before I explicitly set it, PRAGMA temp_store_directory; is blank. I found a reference to it in the source.

export SQLITE_TMPDIR="/data/local/tmp";
export TMPDIR="/data/local/tmp";
export TMP="/data/local/tmp";
export TEMP="/data/local/tmp";
export TMP="/data/local/tmp";
export temp_store_directory="/data/local/tmp";
export TEMP_STORE_DIRECTRORY="/data/local/tmp";

sqlite3 "$sDB_FILE" -batch <<EOF
PRAGMA temp_store_directory = '/data/local/tmp';
-- blah blah blah
EOF

(8) By Warren Young (wyoung) on 2022-10-06 10:49:16 in reply to 7.0 [link] [source]

Hint: code fences (triple backticks) work better for this type of formatting in Markdown.

(9.1) By DiamondJohn on 2022-10-07 07:10:42 edited from 9.0 in reply to 8 [link] [source]

Sorry, new to this forum.

Edited previous post to include triple back ticks

(10) By Dan Kennedy (dan) on 2022-10-06 14:25:23 in reply to 7.0 [link] [source]

Tried the following and it still appears to try and create temp files in /data/local

Who built the shell tool you are using? Does running

    strings sqlite3 | grep /data/local

show anything?

Dan.

(11.1) By DiamondJohn on 2022-10-07 06:59:09 edited from 11.0 in reply to 10 [link] [source]

Its not a "shell tool". It runs under the standard android shell. And hence, the above shell commands.

The actual executable binary was built by myself, and it is literally an unchanged build of the amalgamation http://www.sqlite.org/20??/sqlite-amalgamation-???????.zip. Following the instructions / build from https://github.com/stockrt/sqlite3-android

And "/data/local" is not contained in the strings in the binary. I also checked the source, and I didn't find it there.