From 81c12a35e66f969f683246d3a94434de4a93f8bc Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 24 Feb 2022 02:58:47 +0000 Subject: [PATCH] Fix broken path parsing FossilOrigin-Name: 5040e8d660047072b4b829e4da564e744b8c44c0233ef85ee5a6c7c82e1a2918 --- src/path.c | 19 +++++++++++++------ src/path.h | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/path.c b/src/path.c index 69b8f9f..10edfce 100644 --- a/src/path.c +++ b/src/path.c @@ -28,7 +28,7 @@ enum path_state PARSE_READ, }; -void parse_path(mastodont_t* api, struct path_info* path_info) +int parse_path(mastodont_t* api, struct path_info* path_info) { int fail = 0, fin = 0; enum path_state state = PARSE_NEUTRAL; @@ -77,13 +77,18 @@ void parse_path(mastodont_t* api, struct path_info* path_info) } else { // Don't realloc, we already have a space for our final character - if (p2[i] == '\0') + if (p2[i] == '\0' || p2[i] == '/') { tmp[str_size] = '\0'; ++j; + // Move --i back one to counter the upcoming ++i + // If we don't, then we are one step too far + --i; + } + else { + tmp = realloc(tmp, ++str_size + 1); + tmp[str_size-1] = p2[i]; } - tmp = realloc(tmp, ++str_size + 1); - tmp[str_size-1] = p2[i]; } @@ -95,7 +100,7 @@ void parse_path(mastodont_t* api, struct path_info* path_info) } breakpt: if (fail) - return; + return 1; path_info->callback(api, data, size); @@ -105,6 +110,7 @@ breakpt: free(data[i]); } if (data) free(data); + return 0; } void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len) @@ -118,7 +124,8 @@ void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len) else { // Generic path for (size_t i = 0; i < paths_len; ++i) { - parse_path(api, paths + i); + if (parse_path(api, paths + i) == 0) + return; } } } diff --git a/src/path.h b/src/path.h index 2fdd0ff..5d0f03c 100644 --- a/src/path.h +++ b/src/path.h @@ -28,6 +28,6 @@ struct path_info }; void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len); -void parse_path(mastodont_t* api, struct path_info* path_info); +int parse_path(mastodont_t* api, struct path_info* path_info); #endif // PATH_H