Repository navigation
fix(gateway): session delete lock and partial skill body refusal #129
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
Changes from all commits
5e81668
49e237e
7a9b5ea
fb42340
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| #include "asap/log.h" | ||
| #include "core/agent.h" | ||
| #include "core/bootstrap.h" | ||
| #include "core/dispatch.h" | ||
| #include "core/config.h" | ||
| #include "core/config_patch.h" | ||
| #include "core/memory.h" | ||
|
|
@@ -377,28 +378,75 @@ static void handle_skills_list(const config_t *cfg, char *buf, size_t size, int | |
| #define SKILL_CONTENT_MAX 32768 | ||
| #define MEMORY_RESULTS_MAX 16384 | ||
|
|
||
| static void handle_skill_get(const config_t *cfg, const char *name, char *buf, size_t size, int *status) | ||
| static void skill_too_large(char *buf, size_t size, int *status, const char *name, | ||
| const char *limit_desc) | ||
| { | ||
| char *content = malloc(SKILL_CONTENT_MAX); | ||
| if (!content) { json_error(buf, size, status, 500, "Out of memory"); return; } | ||
| if (skill_get_content(cfg, name, content, SKILL_CONTENT_MAX) != 0) { | ||
| free(content); | ||
| json_error(buf, size, status, 404, "Skill not found"); | ||
| char msg[256]; | ||
| int n; | ||
|
|
||
| n = snprintf(msg, sizeof(msg), "skill \"%s\" exceeds %s", | ||
| name ? name : "", limit_desc ? limit_desc : "edit buffer"); | ||
| if (n < 0 || (size_t)n >= sizeof(msg)) | ||
| json_error(buf, size, status, 413, "skill exceeds edit buffer"); | ||
| else | ||
| json_error(buf, size, status, 413, msg); | ||
| } | ||
|
|
||
| static void skill_get_send(const char *name, const char *content, char *buf, size_t size, | ||
| int *status) | ||
| { | ||
| cJSON *obj; | ||
| char *printed; | ||
| obj = cJSON_CreateObject(); | ||
| if (!obj) { | ||
| json_error(buf, size, status, 500, "Internal error"); | ||
| return; | ||
| } | ||
| cJSON *obj = cJSON_CreateObject(); | ||
| if (!obj) { free(content); json_error(buf, size, status, 500, "Internal error"); return; } | ||
| cJSON_AddItemToObject(obj, "name", cJSON_CreateString(name)); | ||
| cJSON_AddItemToObject(obj, "content", cJSON_CreateString(content)); | ||
| free(content); | ||
| char *s = cJSON_PrintUnformatted(obj); | ||
| printed = cJSON_PrintUnformatted(obj); | ||
| cJSON_Delete(obj); | ||
| if (s) { | ||
| json_response(buf, size, status, s); | ||
| free(s); | ||
| } else { | ||
| if (!printed) { | ||
| json_error(buf, size, status, 500, "Internal error"); | ||
| return; | ||
| } | ||
| /* A cut-off 200 body parses as empty in the dashboard and Save wipes the file. */ | ||
| if (strlen(printed) >= size) { | ||
| char limit_desc[64]; | ||
| free(printed); | ||
| snprintf(limit_desc, sizeof(limit_desc), "%zu byte response buffer", size); | ||
| skill_too_large(buf, size, status, name, limit_desc); | ||
| return; | ||
| } | ||
| json_response(buf, size, status, printed); | ||
| free(printed); | ||
| } | ||
|
|
||
| static void handle_skill_get(const config_t *cfg, const char *name, char *buf, size_t size, int *status) | ||
| { | ||
| char *content; | ||
| int rc; | ||
|
|
||
| content = malloc(SKILL_CONTENT_MAX); | ||
| if (!content) { | ||
| json_error(buf, size, status, 500, "Out of memory"); | ||
| return; | ||
| } | ||
| rc = skill_get_content(cfg, name, content, SKILL_CONTENT_MAX); | ||
| if (rc != 0) { | ||
| free(content); | ||
| if (rc == -2) { | ||
| char limit_desc[64]; | ||
| snprintf(limit_desc, sizeof(limit_desc), "%d byte edit buffer", | ||
| SKILL_CONTENT_MAX - 1); | ||
| skill_too_large(buf, size, status, name, limit_desc); | ||
| } else { | ||
| json_error(buf, size, status, 404, "Skill not found"); | ||
| } | ||
| return; | ||
| } | ||
| skill_get_send(name, content, buf, size, status); | ||
| free(content); | ||
| } | ||
|
|
||
| static void handle_skill_create(const config_t *cfg, const char *body, size_t body_len, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
@@ -508,11 +556,7 @@ static void handle_sessions_list(char *buf, size_t size, int *status) | |
|
|
||
| static void handle_session_delete(const char *id, char *buf, size_t size, int *status) | ||
| { | ||
| int rc; | ||
| agent_lock(); | ||
| rc = session_delete(id); | ||
| agent_unlock(); | ||
| if (rc != 0) { | ||
| if (dispatch_delete_session(id) != 0) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Behaviour is unchanged here: the base already held |
||
| json_error(buf, size, status, 404, "Session not found"); | ||
| return; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
append_file_contentreads withfgetsand advances bystrlen(buf), so a skill file that contains a NUL byte stops counting at the NUL andused < sz. That returns-2, and the dashboard then says the skill "exceeds the edit buffer" for a file of a few hundred bytes. It still fails closed (good), but the message is misleading. Consider a different code (or-1) whensz < out_sizeyetused != sz, and keep-2for the real size case.