Compare commits

...

2 Commits

Author SHA1 Message Date
3606f38890 Add table name validation 2023-01-13 22:21:28 +05:00
06139693c6 Prevent out of bounds when access to empty comma parameter 2023-01-13 22:18:02 +05:00

View File

@ -4,6 +4,7 @@ import (
"bufio"
"database/sql"
"encoding/csv"
"errors"
"fmt"
"io"
"log"
@ -74,6 +75,10 @@ var app = &cli.App{
},
},
Action: func(c *cli.Context) error {
if len(strings.Split(c.String("table"), ".")) != 2 {
return errors.New("table name must be in schema.name format")
}
var err error
db, err = sql.Open("sqlserver", fmt.Sprintf("sqlserver://%s?database=%s", c.String("server"), c.String("database")))
@ -135,7 +140,7 @@ func processReader(c *cli.Context, r io.Reader) error {
reader.TrimLeadingSpace = false
reader.FieldsPerRecord = len(c.String("fields"))
if []rune(c.String("comma"))[0] == 't' {
if runes := []rune(c.String("comma")); len(runes) > 0 && runes[0] == 't' {
reader.Comma = '\t'
} else {
reader.Comma = []rune(c.String("comma"))[0]