Fix unbound variable error in column existence checks#39
Fix unbound variable error in column existence checks#39burakkurkcu wants to merge 1 commit intowebcoyote:mainfrom
Conversation
|
Hi, and thanks for creating a PR for this issue. Can you help me understand the problem? I'm not sure how user data would infect the grep operation because the PRAGMA command is not performing a select on the table data, it's getting back a list of the column names, and grep then counts. Can you help me repro this error in db.sh line 69? |
|
I remember I was at v1.0.11 version then pulled v1.0.18 it was silent exiting at time, then reverted to v1.0.11 again for time. and then seeing @echthesia addressing bug I have I pulled v1.0.21 and it was fine. then I pulled today latest commit with merge tart message, I started getting error below. To be honest I didn't get it as it seems just a thing from migration side code which should just pass by because I already migrated before. so I threw db.sh to claude to try a quick fix to get going at first. and this is it. after error gone these logs occured.
when I have some more time I can try same repro path by reverting to .11 create vm and everything, and then to latest commit in today to see if it can repro. |

Summary
Fixes an
unbound variableerror that could occur during database migration when the column-existence checks ininit_dbreceived non-numeric input.Problem
The migration logic for adding
ram_mb,base_name, andssh_usercolumns used:The
-eqoperator evaluates both sides in arithmetic context, which treats bare words as variable names. If the captured value ever contained something non-numeric (e.g. a path like/Users/...leaking into the pipeline), bash would parseUsersas a variable reference and — withset -uactive — fail with:The
|| truefallback was also masking genuinesqlite3failures, letting migrations silently no-op.Fix
column_existshelper that relies ongrep -q's exit status, avoiding arithmetic context entirely.|column|to match against pipe-delimitedPRAGMA table_infooutput and prevent false matches on column name prefixes (e.g.ram_mbmatchingram_mb_limit).has_*checks withif ! column_exists instances <col>.|| truefallbacks so real sqlite3 errors surface instead of being swallowed.Testing
$DB_FILE— all three columns created as expected.set -uno longer trips on the migration path.Risk
Low. Pure refactor of internal migration logic; no schema or API changes. The new helper is private to
db.sh.