Skip to content

Commit

Permalink
DEVEX-1930 Use prepared SQL statements with filenames (#67)
Browse files Browse the repository at this point in the history
* Prepare SQL statements with filenames to support single quote in filename

* Bump version to v0.24.2
  • Loading branch information
kpjensen authored Jun 3, 2021
1 parent 8551c08 commit 32ddb89
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions metadata_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,11 +751,10 @@ func (mdb *MetadataDb) createDataObject(
return 0, oph.RecordError(err)
}

sqlStmt = fmt.Sprintf(`
INSERT INTO namespace
VALUES ('%s', '%s', '%d', '%d');`,
parentDir, fname, nsDataObjType, inode)
if _, err := oph.txn.Exec(sqlStmt); err != nil {
sqlStatementPrep, _ := oph.txn.Prepare(`INSERT INTO namespace
VALUES ($1, $2, $3, $4);`)
defer sqlStatementPrep.Close()
if _, err := sqlStatementPrep.Exec(parentDir, fname, nsDataObjType, inode); err != nil {
mdb.log("Error inserting %s/%s into the namespace table err=%s", parentDir, fname, err.Error())
return 0, oph.RecordError(err)
}
Expand Down Expand Up @@ -1132,12 +1131,13 @@ func (mdb *MetadataDb) LookupInDir(ctx context.Context, oph *OpHandle, dir *Dir,
}

// point lookup in the namespace
sqlStmt := fmt.Sprintf(`
SELECT obj_type,inode
FROM namespace
WHERE parent = '%s' AND name = '%s';`,
dir.FullPath, dirOrFileName)
rows, err := oph.txn.Query(sqlStmt)
sqlStmtPrep, _ := oph.txn.Prepare(`
SELECT obj_type,inode
FROM namespace
WHERE parent = ? AND name = ?;`)
defer sqlStmtPrep.Close()
rows, err := sqlStmtPrep.Query(dir.FullPath, dirOrFileName)

if err != nil {
return nil, false, oph.RecordError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions test/correctness/code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ main() {
mkdir -p $mountpoint

# generate random alphanumeric strings
base_dir=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)
base_dir=$(dd if=/dev/urandom bs=15 count=1 2>/dev/null| base64 | tr -dc 'a-zA-Z0-9'|fold -w 12|head -n1)
base_dir="base_$base_dir"
faux_dir=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)
faux_dir=$(dd if=/dev/urandom bs=15 count=1 2>/dev/null| base64 | tr -dc 'a-zA-Z0-9'|fold -w 12|head -n1)
faux_dir="faux_$faux_dir"
expr_dir=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)
expr_dir=$(dd if=/dev/urandom bs=15 count=1 2>/dev/null| base64 | tr -dc 'a-zA-Z0-9'|fold -w 12|head -n1)
expr_dir="expr_$expr_dir"
writeable_dirs=($base_dir $faux_dir $expr_dir)
for d in ${writeable_dirs[@]}; do
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
MaxDirSize = 255 * 1000
MaxNumFileHandles = 1000 * 1000
NumRetriesDefault = 10
Version = "v0.24.1"
Version = "v0.24.2"
)
const (
InodeInvalid = 0
Expand Down

0 comments on commit 32ddb89

Please sign in to comment.