From a5690bc3bf2fc59ca89fe9b4e20b6b66212969fa Mon Sep 17 00:00:00 2001 From: Nikita Wootten Date: Fri, 22 Apr 2022 18:11:55 -0400 Subject: [PATCH 1/2] Create codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 70 +++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..27f1a51 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,70 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '16 4 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 From c0c6876c837a8216d1dab78f761bf954b495b0f5 Mon Sep 17 00:00:00 2001 From: Nikita Wootten Date: Thu, 12 May 2022 21:15:20 -0400 Subject: [PATCH 2/2] Fix code scanning alert - Incorrect conversion between integer types Fixes #99 --- save.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/save.go b/save.go index d779f37..24c69b4 100644 --- a/save.go +++ b/save.go @@ -499,6 +499,10 @@ func generateCurRels(gogm *Gogm, parentPtr uintptr, current *reflect.Value, curr // createNodes updates existing nodes and creates new nodes while also making a lookup table for ptr -> neoid func createNodes(transaction neo4j.Transaction, crNodes map[string]map[uintptr]*nodeCreate, nodeRef map[uintptr]*reflect.Value, nodeIdRef map[uintptr]int64) error { for label, nodes := range crNodes { + // used when the id of the node hasn't been set yet + var i uint64 = 0 + var nodesArr []*nodeCreate + var updateRows, newRows []interface{} for ptr, config := range nodes { row := map[string]interface{}{ @@ -509,9 +513,12 @@ func createNodes(transaction neo4j.Transaction, crNodes map[string]map[uintptr]* row["id"] = id updateRows = append(updateRows, row) } else { - row["ptr"] = fmt.Sprintf("%v", ptr) + row["i"] = fmt.Sprintf("%d", i) newRows = append(newRows, row) } + + nodesArr = append(nodesArr, config) + i++ } // create new stuff @@ -521,8 +528,8 @@ func createNodes(transaction neo4j.Transaction, crNodes map[string]map[uintptr]* Cypher(fmt.Sprintf("CREATE(n:`%s`)", label)). Cypher("SET n += row.obj"). Return(false, dsl.ReturnPart{ - Name: "row.ptr", - Alias: "ptr", + Name: "row.i", + Alias: "i", }, dsl.ReturnPart{ Function: &dsl.FunctionConfig{ Name: "ID", @@ -555,25 +562,30 @@ func createNodes(transaction neo4j.Transaction, crNodes map[string]map[uintptr]* return fmt.Errorf("cannot cast row[0] to string, %w", ErrInternal) } - ptrInt, err := strconv.ParseUint(strPtr, 10, 64) + i, err = strconv.ParseUint(strPtr, 10, 64) if err != nil { - return fmt.Errorf("failed to parse ptr string to int64, %w", err) + return fmt.Errorf("failed to parse i string to uint64, %w", err) } - ptr := uintptr(ptrInt) + if i > uint64(len(nodesArr)) { + return fmt.Errorf("returned node index %d is outside of node array bounds", i) + } graphId, ok := row[1].(int64) if !ok { return fmt.Errorf("cannot cast row[1] to int64, %w", ErrInternal) } + // get node reference from index + ptr := nodesArr[i].Pointer + // update the lookup nodeIdRef[ptr] = graphId - //set the new id + // set the new id val, ok := nodeRef[ptr] if !ok { - return fmt.Errorf("cannot find val for ptr [%v]", ptr) + return fmt.Errorf("cannot find val for ptr [%d]", ptr) } reflect.Indirect(*val).FieldByName(DefaultPrimaryKeyStrategy.FieldName).Set(reflect.ValueOf(&graphId))