Server error with slightly incorrect delete request #47

Open
opened 2020-04-25 19:52:33 +02:00 by fumyuun · 3 comments

I made a small typo with a delete request and got the following server error:

internal server error: runtime error: invalid memory address or nil pointer dereference

The request I tried to do was:
curl --request "DELETE" "https://hashru.link/Dwf_jpeg?deleteToken=a00e1f62d2c2f80f3c75ed425954e65e"
(missing dot in front of the jpeg)

I made a small typo with a delete request and got the following server error: `internal server error: runtime error: invalid memory address or nil pointer dereference` The request I tried to do was: `curl --request "DELETE" "https://hashru.link/Dwf_jpeg?deleteToken=a00e1f62d2c2f80f3c75ed425954e65e"` (missing dot in front of the jpeg)
Collaborator

Your request matches urlKeyExpr instead of urlKeyWithExtExpr. This means Dwf_jpeg is parsed as the paste key.

There probably is no paste with this key. I haven't found where the nil pointer dereference comes from yet.

Your request matches [urlKeyExpr](https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/router.go#L18) instead of [urlKeyWithExtExpr](https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/router.go#L19). This means `Dwf_jpeg` is parsed as the paste key. There probably is no paste with this key. I haven't found where the nil pointer dereference comes from yet.
Collaborator

Found it. In https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/internal/db/paste.go#L96, nil, nil is returned when a paste with the given key is not found. The calling code assumes that a non-nil paste is returned if err == nil.

Found it. In https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/internal/db/paste.go#L96, `nil, nil` is returned when a paste with the given key is not found. The [calling code](https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/handlers.go#L310) assumes that a non-`nil` paste is returned if `err == nil`.
electricdusk added the
bug
label 2020-04-26 16:49:43 +02:00
Collaborator

(from an out-of-band discussion:) It would be fine to either add a custom error (e.g. similar to os.ErrFileNotExists), or add a bool return value that is set to false when a paste does not exist.

(from an out-of-band discussion:) It would be fine to either add a custom `error` (e.g. similar to `os.ErrFileNotExists`), or add a `bool` return value that is set to `false` when a paste does not exist.
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: electricdusk/rushlink#47
No description provided.