Skip to content

Commit 37ca7a4

Browse files
Potential fix for code scanning alert no. 368: Potentially unsafe quoting
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 89e8ed6 commit 37ca7a4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sql/rowexec/show_iters.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ func convertColumnDefaultToString(ctx *sql.Context, def *sql.ColumnDefaultValue)
398398
if types.IsBit(def.OutType) {
399399
return fmt.Sprintf("b'%b'", v), nil
400400
}
401-
return fmt.Sprintf("'%v'", v), nil
401+
// Escape single quotes and backslashes in v to prevent SQL injection
402+
sanitizedValue := strings.ReplaceAll(fmt.Sprintf("%v", v), `\`, `\\`)
403+
sanitizedValue = strings.ReplaceAll(sanitizedValue, `'`, `\'`)
404+
return fmt.Sprintf("'%s'", sanitizedValue), nil
402405
}
403406

404407
func (i *showCreateTablesIter) produceCreateTableStatement(ctx *sql.Context, table sql.Table, schema sql.Schema, pkSchema sql.PrimaryKeySchema) (string, error) {

0 commit comments

Comments
 (0)