Show 404 message instead of crashing when requesting a file that isn't there #21

Closed
TheStranjer wants to merge 0 commits from master into master
TheStranjer commented 2019-12-19 03:28:25 +01:00 (Migrated from github.com)

When you request a file that doesn't exist, 0x0 crashes:

thestranjer@monolith:~$ curl http://0x0.st/non_existent_file.txt
<pre>Process 16 stopped
* thread #1: tid = 16, 0x00007f9e6f4d84e0, name = 'fhost'
    frame #0:
Process 16 stopped
* thread #8: tid = 16, 0x00007f9e51d0ad08 fhost`get(path='/non_existent_file.txt') + 27 at fhost.c:139, name = 'fhost/responder', stop reason = invalid address (fault address: 0x30)
    frame #0: 0x00007f9e51d0ad08 fhost`get(path='/non_existent_file.txt') + 27 at fhost.c:139
   136   get(SrvContext *ctx, const char *path)
   137   {
   138       StoredObj *obj = ctx->store->query(shurl_debase(path));
-> 139       switch (obj->type) {
   140           case ObjTypeFile:
   141               ctx->serve_file_id(obj->id);
   142               break;
(lldb) q</pre>

I fix this error with this commit. It returns an answer that is human comprehensible:

thestranjer@monolith:~$ curl http://localhost:5000/non_existent_file.txt
404 File Not Found: /non_existent_file.txt

It does not use the abort() call in the interest of returning human-comprehensible text.

When you request a file that doesn't exist, 0x0 crashes: ``` thestranjer@monolith:~$ curl http://0x0.st/non_existent_file.txt <pre>Process 16 stopped * thread #1: tid = 16, 0x00007f9e6f4d84e0, name = 'fhost' frame #0: Process 16 stopped * thread #8: tid = 16, 0x00007f9e51d0ad08 fhost`get(path='/non_existent_file.txt') + 27 at fhost.c:139, name = 'fhost/responder', stop reason = invalid address (fault address: 0x30) frame #0: 0x00007f9e51d0ad08 fhost`get(path='/non_existent_file.txt') + 27 at fhost.c:139 136 get(SrvContext *ctx, const char *path) 137 { 138 StoredObj *obj = ctx->store->query(shurl_debase(path)); -> 139 switch (obj->type) { 140 case ObjTypeFile: 141 ctx->serve_file_id(obj->id); 142 break; (lldb) q</pre> ``` I fix this error with this commit. It returns an answer that is human comprehensible: ``` thestranjer@monolith:~$ curl http://localhost:5000/non_existent_file.txt 404 File Not Found: /non_existent_file.txt ``` It does not use the `abort()` call in the interest of returning human-comprehensible text.
CounterPillow commented 2019-12-19 04:22:13 +01:00 (Migrated from github.com)

I think you are missing the joke

I think you are missing the joke
TheStranjer commented 2019-12-19 04:45:42 +01:00 (Migrated from github.com)

You're right. I did.

You're right. I did.

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 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: mia/0x0#21
No description provided.