humanmade / go-anonymize-mysqldump

Allows you to pipe data from mysqldump or an SQL file and anonymize it.
GNU General Public License v3.0
60 stars 25 forks source link

Crash if asked to replace a value which can be NULL #6

Open PatrickLerner opened 4 years ago

PatrickLerner commented 4 years ago

Given a database like

DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`email` varchar(255),
);
INSERT INTO `test` VALUES ('foo'), (NULL), ('hodger');

if you use a config like

{
  "patterns": [
    {
      "tableName": "test",
      "fields": [
        {
          "field": "email",
          "position": 1,
          "type": "email",
          "constraints": null
        }
      ]
    }
  ]
}

the tool will crash with a panic:

panic: interface conversion: sqlparser.Expr is *sqlparser.NullVal, not *sqlparser.SQLVal

goroutine 35 [running]:
main.modifyValues(0xc0003f6060, 0x3, 0x4, 0xc00008e2f8, 0x4, 0xc0001e6000, 0x1, 0x4, 0x0, 0x0, ...)
    /Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:299 +0x572
main.applyConfigToInserts(0xc00041a0b0, 0xc0001e4000, 0x1, 0x4, 0x0, 0x0, 0x0)
    /Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:277 +0x1f9
main.applyConfigToParsedLine(0x126f020, 0xc00041a0b0, 0xc0001e4000, 0x1, 0x4, 0x0, 0x0, 0x0, 0x0)
    /Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:250 +0x68
main.processLine(0xc0001cc1c0, 0x36, 0xc0001e4000, 0x1, 0x4, 0x0, 0x0)
    /Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:218 +0x2c1
main.processInput.func1(0xc00008e320, 0xc0001e4000, 0x1, 0x4, 0xc0003f20c0, 0xc0001cc1c0, 0x36)
    /Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:194 +0xab
created by main.processInput
    /Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:192 +0x41c

If NULL does not appear, it works fine.

NikolaiGulatz commented 4 years ago

@PatrickLerner please see my PR which fixes this issue by ignoring NULL values in transformable fields.

jasperoosthoek commented 4 years ago

I'm running into this issue right now and would appreciate if this PR gets merged!

fadiadawi commented 3 years ago

I used this PR and still getting the same error. Please help. I am building it on my mac using the following command GOOS=linux GOARCH=amd64 go build -v github.com/NikolaiGulatz/go-anonymize-mysqldump The build is success but same issue with the null values

PatrickLerner commented 3 years ago

Hey @fadiadawi,

When I compiled the binary from Nikolai's branch, I did it like so:

docker run -e GOOS=linux -e GOARCH=amd64 -v /tmp/crosstest:/go/bin golang bash -c "git clone 'https://github.com/NikolaiGulatz/go-anonymize-mysqldump.git' /go/src/go-anonymize-mysqldump && cd /go/src/go-anonymize-mysqldump && git checkout fix-for-null-values && go get . && go build"

I think the issue is that go does not check out the feature branch? I also remember that this was explicitly not a feature in go to build it from a branch for some reason or another (I don't use go usually).

Hope it helps 🤞

fadiadawi commented 3 years ago

Hello and thank you for your reply. I am trying to run this command on my mac (host) . I tried:

GOOS=linux -e GOARCH=amd64 -v git clone 'https://github.com/NikolaiGulatz/go-anonymize-mysqldump.git' /go/src/go-anonymize-mysqldump && cd /go/src/go-anonymize-mysqldump && git checkout fix-for-null-values && go get . && go build but did not work. I also removed -r and -v and built a file but when I tried to run it I got an error saying that the file has incorrect format

On Wed, Feb 10, 2021 at 11:12 PM Patrick Lerner notifications@github.com wrote:

Hey @fadiadawi https://github.com/fadiadawi,

When I compiled the binary from Nikolai's branch, I did it like so:

docker run -e GOOS=linux -e GOARCH=amd64 -v /tmp/crosstest:/go/bin golang bash -c "git clone 'https://github.com/NikolaiGulatz/go-anonymize-mysqldump.git' /go/src/go-anonymize-mysqldump && cd /go/src/go-anonymize-mysqldump && git checkout fix-for-null-values && go get . && go build"

I think the issue is that go does not check out the feature branch? I also remember that this was explicitly not a feature in go to build it from a branch for some reason or another (I don't use go usually).

Hope it helps 🤞

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/humanmade/go-anonymize-mysqldump/issues/6#issuecomment-777244937, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASJUI25IAFBJKBDV6Z7FIRLS6N7OLANCNFSM4KMC3CEA .

PatrickLerner commented 3 years ago

Are you trying to run a linux binary on mac?

Maybe try this or similar:

docker run -e GOOS=darwin -e GOARCH=amd64 -v /tmp/crosstest:/go/bin golang bash -c "git clone 'https://github.com/NikolaiGulatz/go-anonymize-mysqldump.git' /go/src/go-anonymize-mysqldump && cd /go/src/go-anonymize-mysqldump && git checkout fix-for-null-values && go get . && go build"

if you need a mac binary :)

fadiadawi commented 3 years ago

I tried but when I attempt to execute the file, I get this error: "cannot execute binary file: Exec format error"

On Thu, Feb 11, 2021 at 12:35 AM Patrick Lerner notifications@github.com wrote:

Are you trying to run a linux binary on mac?

Maybe try this or similar:

docker run -e GOOS=darwin -e GOARCH=amd64 -v /tmp/crosstest:/go/bin golang bash -c "git clone 'https://github.com/NikolaiGulatz/go-anonymize-mysqldump.git' /go/src/go-anonymize-mysqldump && cd /go/src/go-anonymize-mysqldump && git checkout fix-for-null-values && go get . && go build"

if you need a mac binary :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/humanmade/go-anonymize-mysqldump/issues/6#issuecomment-777278464, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASJUI2YOZVRJDKYFTV4M7MTS6OJD7ANCNFSM4KMC3CEA .

fadiadawi commented 3 years ago

I got it to work using a different approach. I forked the fix and created my own repo on GitHub. I was then able to build successfully using this : GOOS=linux GOARCH=amd64 go build -v github.com/my_user_name/go-anonymize-mysqldump I am not a GO coder. Thank you for all the help. I really appreciate it :)

On Thu, Feb 11, 2021 at 12:52 AM Fadi Adawi < fadi.adawi@foresightmentalhealth.com> wrote:

I tried but when I attempt to execute the file, I get this error: "cannot execute binary file: Exec format error"

On Thu, Feb 11, 2021 at 12:35 AM Patrick Lerner notifications@github.com wrote:

Are you trying to run a linux binary on mac?

Maybe try this or similar:

docker run -e GOOS=darwin -e GOARCH=amd64 -v /tmp/crosstest:/go/bin golang bash -c "git clone 'https://github.com/NikolaiGulatz/go-anonymize-mysqldump.git' /go/src/go-anonymize-mysqldump && cd /go/src/go-anonymize-mysqldump && git checkout fix-for-null-values && go get . && go build"

if you need a mac binary :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/humanmade/go-anonymize-mysqldump/issues/6#issuecomment-777278464, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASJUI2YOZVRJDKYFTV4M7MTS6OJD7ANCNFSM4KMC3CEA .