Skip to content

Commit

Permalink
Fixed array bounds issue parsing mysql db meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Jeannopoulos committed Jul 13, 2020
1 parent 3d35fac commit daf364d
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 18 deletions.
12 changes: 8 additions & 4 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _test/dbmeta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
goopt.Description = func() string {
return "ORM and RESTful meta data viewer for SQl databases"
}
goopt.Version = "v0.9.23 (07/10/2020)"
goopt.Version = "v0.9.24 (07/13/2020)"
goopt.Summary = `dbmeta [-v] --sqltype=mysql --connstr "user:password@/dbname" --database <databaseName>
sqltype - sql database type such as [ mysql, mssql, postgres, sqlite, etc. ]
Expand Down
4 changes: 2 additions & 2 deletions code_http.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func GetInvoices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// @Failure 400 {object} api.HTTPError
// @Failure 404 {object} api.HTTPError
// @Router /invoices [post]
// echo '{"billing_city": "OZXsAdCPKOjTctytoYEwgOtYE","billing_state": "UOfAdBkzjGadsbbjkkhozikYw","billing_postal_code": "GXmsXWLgcCWXRUcuGACWkBVTP","billing_address": "HeOCpxWwhFWfMdiJUZDwKymnA","billing_country": "XiLGkZMtOvVGXsoPVWIIzVCQI","total": 0.10089232722813705,"invoice_id": 97,"customer_id": 7,"invoice_date": "2044-08-15T16:02:07.572705306-05:00"}' | http POST "http://127.0.0.1:8080/invoices" X-Api-User:user123
// echo '{"billing_city": "cjuHwSGtQsvxoudomCbYKIpzZ","billing_state": "ZYmdoDEweNWlqtWNoZnIoLHSU","billing_postal_code": "EXQosbeNyzdoEZxEsunUdwKab","total": 0.4938656834813154,"invoice_id": 72,"customer_id": 86,"invoice_date": "2092-01-02T22:21:00.61433147-05:00","billing_address": "dfaDgvowdMJWOQrTfwwNUVAcN","billing_country": "igXpMTfRsqHWhALluklMJLYZK"}' | http POST "http://127.0.0.1:8080/invoices" X-Api-User:user123
func AddInvoices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
ctx := initializeContext(r)
invoices := &model.Invoices{}
Expand Down Expand Up @@ -192,7 +192,7 @@ func AddInvoices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// @Failure 400 {object} api.HTTPError
// @Failure 404 {object} api.HTTPError
// @Router /invoices/{argInvoiceID} [patch]
// echo '{"billing_city": "OZXsAdCPKOjTctytoYEwgOtYE","billing_state": "UOfAdBkzjGadsbbjkkhozikYw","billing_postal_code": "GXmsXWLgcCWXRUcuGACWkBVTP","billing_address": "HeOCpxWwhFWfMdiJUZDwKymnA","billing_country": "XiLGkZMtOvVGXsoPVWIIzVCQI","total": 0.10089232722813705,"invoice_id": 97,"customer_id": 7,"invoice_date": "2044-08-15T16:02:07.572705306-05:00"}' | http PUT "http://127.0.0.1:8080/invoices/1" X-Api-User:user123
// echo '{"billing_city": "cjuHwSGtQsvxoudomCbYKIpzZ","billing_state": "ZYmdoDEweNWlqtWNoZnIoLHSU","billing_postal_code": "EXQosbeNyzdoEZxEsunUdwKab","total": 0.4938656834813154,"invoice_id": 72,"customer_id": 86,"invoice_date": "2092-01-02T22:21:00.61433147-05:00","billing_address": "dfaDgvowdMJWOQrTfwwNUVAcN","billing_country": "igXpMTfRsqHWhALluklMJLYZK"}' | http PUT "http://127.0.0.1:8080/invoices/1" X-Api-User:user123
func UpdateInvoices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
ctx := initializeContext(r)

Expand Down
2 changes: 1 addition & 1 deletion dbmeta/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (c *Config) CreateContextForTableFile(tableInfo *ModelInfo) map[string]inte
}

// WriteTemplate write a template out
func (c *Config) WriteTemplate(genTemplate *GenTemplate, data map[string]interface{}, outputFile string, formatOutput bool) error{
func (c *Config) WriteTemplate(genTemplate *GenTemplate, data map[string]interface{}, outputFile string, formatOutput bool) error {
if !c.Overwrite && Exists(outputFile) {
fmt.Printf("not overwriting %s\n", outputFile)
return nil
Expand Down
4 changes: 3 additions & 1 deletion dbmeta/meta_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func LoadMysqlMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableM
if commentIdx > -1 {
re := regexp.MustCompile("COMMENT '(.*?)'")
match := re.FindStringSubmatch(colDDL)
comment = match[1]
if len(match) > 0 {
comment = match[1]
}
}

if infoSchema != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ require (
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/spf13/cobra v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/tools v0.0.0-20200630154851-b2d8b0336632 // indirect
golang.org/x/tools v0.0.0-20200711155855-7342f9734a7d // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20200608115520-7c474a2e3482 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
Expand Down
6 changes: 1 addition & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func init() {
goopt.Description = func() string {
return "ORM and RESTful API generator for SQl databases"
}
goopt.Version = "v0.9.23 (07/10/2020)"
goopt.Version = "v0.9.24 (07/13/2020)"
goopt.Summary = `gen [-v] --sqltype=mysql --connstr "user:password@/dbname" --database <databaseName> --module=example.com/example [--json] [--gorm] [--guregu] [--generate-dao] [--generate-proj]
git fetch up
sqltype - sql database type such as [ mysql, mssql, postgres, sqlite, etc. ]
Expand Down Expand Up @@ -602,7 +602,6 @@ func generate(conf *dbmeta.Config) error {
os.Exit(1)
}


if *modGenerate {
err = conf.WriteTemplate(GoModuleTmpl, data, filepath.Join(*outDir, "go.mod"), false)
if err != nil {
Expand Down Expand Up @@ -735,7 +734,6 @@ func generateProtobufDefinitionFile(conf *dbmeta.Config, data map[string]interfa
os.Exit(1)
}


compileOutput, err := CompileProtoC(*outDir, moduleDir, filepath.Join(*outDir, protofile))
if err != nil {
fmt.Print(au.Red(fmt.Sprintf("Error compiling proto file %v\n", err)))
Expand All @@ -757,7 +755,6 @@ func generateProtobufDefinitionFile(conf *dbmeta.Config, data map[string]interfa
os.Exit(1)
}


if ProtobufTmpl, err = LoadTemplate("protoserver.go.tmpl"); err != nil {
fmt.Print(au.Red(fmt.Sprintf("Error loading template %v\n", err)))
return err
Expand All @@ -769,7 +766,6 @@ func generateProtobufDefinitionFile(conf *dbmeta.Config, data map[string]interfa
os.Exit(1)
}


return nil
}

Expand Down
Loading

0 comments on commit daf364d

Please sign in to comment.