Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashed after executing the command #464

Open
spance opened this issue May 13, 2024 · 10 comments
Open

Crashed after executing the command #464

spance opened this issue May 13, 2024 · 10 comments

Comments

@spance
Copy link

spance commented May 13, 2024

~$ ./usql_static -V
usql 0.19.1
~$ ./usql_static
Type "help" for help.

panic: runtime error: slice bounds out of range [:43] with capacity 32

goroutine 1 [running]:
github.com/xo/usql/stmt.(*Params).Get(0xc00077c720, 0xc00173ea48)
        github.com/xo/usql/stmt/params.go:86 +0x9fb
github.com/xo/usql/stmt.(*Params).GetAll(0xc00077c720, 0xc00173ea48)
        github.com/xo/usql/stmt/params.go:97 +0x55
github.com/xo/usql/metacmd.(*Params).GetAll(0xc000c320c0, 0x1)
        github.com/xo/usql/metacmd/types.go:202 +0x192
github.com/xo/usql/metacmd.init.0.func15(0xc000c320c0)
        github.com/xo/usql/metacmd/cmds.go:442 +0x178
github.com/xo/usql/handler.(*Handler).Run.Decode.func3({0x6e2e518, 0xc001677200})
        github.com/xo/usql/metacmd/metacmd.go:26 +0xd8
github.com/xo/usql/metacmd.RunnerFunc.Run(0x585b8e0?, {0x6e2e518?, 0xc001677200?})
        github.com/xo/usql/metacmd/types.go:82 +0x4d
github.com/xo/usql/handler.(*Handler).Run(0xc001677200)
        github.com/xo/usql/handler/handler.go:282 +0xb30
main.Run({0x6dd1b40, 0xada1340}, 0xc0010e5a70, 0xc000ca12c0, {0xc000eff020, 0x23})
        github.com/xo/usql/run.go:355 +0xce2
main.New.func3(0xc001407808?, {0xada1340?, 0x7?, 0x6077847?})
        github.com/xo/usql/run.go:126 +0x185
github.com/spf13/cobra.(*Command).execute(0xc001407808, {0xc0000740a0, 0x0, 0x0})
        github.com/spf13/[email protected]/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc001407808)
        github.com/spf13/[email protected]/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/[email protected]/command.go:1039
github.com/spf13/cobra.(*Command).ExecuteContext(0xc0000740a0?, {0x6dd1b40?, 0xada1340?})
        github.com/spf13/[email protected]/command.go:1032 +0x47
main.main()
        github.com/xo/usql/main.go:40 +0x13c
@nineinchnick
Copy link
Member

What's in your $HOME/.usqlrc? What's usql_static - how did you build it?

@spance
Copy link
Author

spance commented May 13, 2024

The .usqlrc is an empty file, and the usql_static was downloaded from https://github.com/xo/usql/releases/download/v0.19.1/usql_static-0.19.1-linux-amd64.tar.bz2

@nineinchnick
Copy link
Member

Are you sure it's empty? It fails when executing an \echo command, I wonder how it's being triggered and what are the arguments to it. Can you try running it with -X? This disables reading any init files.

@spance
Copy link
Author

spance commented May 13, 2024

I tried many times and finally found the problem.
My config file $HOME/.config/usql/config.yaml like this:

connections:
  xxx: xxxx
init: |
  \echo date `date`

Then after deleting the init fragment, no errors were reported.

@nineinchnick
Copy link
Member

Oh I totally forgot there's a yaml config too, thanks! @kenshaw PTAL, \echo date date`` works with a regular .usqlrc.

@kenshaw
Copy link
Member

kenshaw commented May 13, 2024

I'll look in to this shortly. Probably a simple oversight on my part.

@kenshaw
Copy link
Member

kenshaw commented May 13, 2024

I'm not able to reproduce this error:

ken@ken-desktop:~/Downloads$ mkdir usql
ken@ken-desktop:~/Downloads$ cd usql/
[config.yaml.txt](https://github.com/xo/usql/files/15292979/config.yaml.txt)
ken@ken-desktop:~/Downloads/usql$ mv ../usql_static-0.19.1-linux-amd64.tar.bz2 .
ken@ken-desktop:~/Downloads/usql$ tar -jxvf usql_static-0.19.1-linux-amd64.tar.bz2 
usql_static
LICENSE
ken@ken-desktop:~/Downloads/usql$ md5sum usql_static
c110e337bb43dd359c34813bb459366c  usql_static
ken@ken-desktop:~/Downloads/usql$ ./usql_static 
Type "help" for help.

date Mon May 13 05:18:34 PM WIB 2024
(not connected)=> \q
ken@ken-desktop:~/Downloads/usql$ cat ~/.config/usql/config.yaml 
---
init: |
  \echo date `date`
ken@ken-desktop:~/Downloads/usql$ ./usql_static -V
usql 0.19.1
ken@ken-desktop:~/Downloads/usql$ 

Can you please share your exact yaml config file? Note that GitHub doesn't seem to allow uploads of .yaml extensions, for whatever reason. You'll need to rename the file prior to upload.

This is the simple debugging config file that I used:
config.txt

@kenshaw
Copy link
Member

kenshaw commented May 13, 2024

Are you perhaps using something like Windows encoding? With \r\n line endings? I've tried all manner of variations and I can't cause that same block of code to escape under any input that I could come up with. I'm sure my code is bad, but it's going to be difficult to figure out the cause of this without the exact character sequence/input.

Are you able to get \echo to work in the init: stanza in a simpler form? For example:

init: '\echo hi'

Which has this output on my system:

$ usql
Type "help" for help.

hi
(not connected)=> \q

@spance
Copy link
Author

spance commented May 14, 2024

I repeat it again.

~$ cat .config/usql/config.yaml
connections:
  xx: mysql://xxxx
  cr: mysql://xxxx
init: |
  \echo `date`

~$ ./usql
Type "help" for help.

panic: runtime error: slice bounds out of range [:43] with capacity 32

goroutine 1 [running]:
github.com/xo/usql/stmt.(*Params).Get(0xc000d0f660, 0xc00173ea28)
        github.com/xo/usql/stmt/params.go:86 +0x9fb
github.com/xo/usql/metacmd.(*Params).Get(0xc00174ef00, 0x1)
        github.com/xo/usql/metacmd/types.go:164 +0x192
github.com/xo/usql/metacmd.(*Params).GetOptional(0xc0007763c0?, 0xa0?)
        github.com/xo/usql/metacmd/types.go:189 +0x13
github.com/xo/usql/metacmd.init.0.func15(0xc00174ef00)
        github.com/xo/usql/metacmd/cmds.go:428 +0x2c
github.com/xo/usql/handler.(*Handler).Run.Decode.func3({0x6c8a398, 0xc0015fa9c0})
        github.com/xo/usql/metacmd/metacmd.go:26 +0xd8
github.com/xo/usql/metacmd.RunnerFunc.Run(0x56b4360?, {0x6c8a398?, 0xc0015fa9c0?})
        github.com/xo/usql/metacmd/types.go:82 +0x4d
github.com/xo/usql/handler.(*Handler).Run(0xc0015fa9c0)
        github.com/xo/usql/handler/handler.go:282 +0xb30
main.Run({0x6c2d9c0, 0xabad740}, 0xc001277cb0, 0xc000f22bd0, {0xc000f0cd40, 0xd})
        github.com/xo/usql/run.go:355 +0xce2
main.New.func3(0xc00012d808?, {0xabad740?, 0x7?, 0x5ed2453?})
        github.com/xo/usql/run.go:126 +0x185
github.com/spf13/cobra.(*Command).execute(0xc00012d808, {0xc0000740a0, 0x0, 0x0})
        github.com/spf13/[email protected]/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc00012d808)
        github.com/spf13/[email protected]/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/[email protected]/command.go:1039
github.com/spf13/cobra.(*Command).ExecuteContext(0xc0000740a0?, {0x6c2d9c0?, 0xabad740?})
        github.com/spf13/[email protected]/command.go:1032 +0x47
main.main()
        github.com/xo/usql/main.go:40 +0x13c
~$
~$ vim .config/usql/config.yaml
~$ cat .config/usql/config.yaml
connections:
  xx: mysql://xxxx
  cr: mysql://xxxx

~$
~$ ./usql
Type "help" for help.

(not connected)=> \q
~$

@spance
Copy link
Author

spance commented May 14, 2024

Now I found the cause of this problem, because the output of the date command contains some unicode characters (non-ascii), causing the variable i calculation in the Params.Get() method to become longer.
There is my simple fix:

i = start + len([]rune(z)) - 1   // Line-59

Another solution: utf8.RuneCountInString(z)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants