diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2024-02-06 21:38:29 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2024-02-06 21:38:29 -0500 |
commit | f8378d3ca44c93e14dfc16ce5f035446c75d657d (patch) | |
tree | 79b02e3c0148ec980789a407e9d08d7338b08b95 /src/lpm.c | |
parent | 052db5d4be2cde203636e954e8ad9897d3ccc7fc (diff) | |
download | lite-xl-plugin-manager-f8378d3ca44c93e14dfc16ce5f035446c75d657d.tar.gz lite-xl-plugin-manager-f8378d3ca44c93e14dfc16ce5f035446c75d657d.zip |
Doubled response header buffer, added in better error handling for responses, and added in logging and checksum updating of remote file singletons.
Diffstat (limited to 'src/lpm.c')
-rw-r--r-- | src/lpm.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -46,6 +46,8 @@ #include <Security/Security.h> #endif +#define HTTPS_RESPONSE_HEADER_BUFFER_LENGTH 8192 + #if _WIN32 static LPCWSTR lua_toutf16(lua_State* L, const char* str) { @@ -922,7 +924,7 @@ static int lpm_get(lua_State* L) { } const char* rest = luaL_checkstring(L, 4); - char buffer[4096]; + char buffer[HTTPS_RESPONSE_HEADER_BUFFER_LENGTH]; int buffer_length = snprintf(buffer, sizeof(buffer), "GET %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", rest, hostname); buffer_length = lpm_socket_write(s, buffer, buffer_length, ssl_ctx); if (buffer_length < 0) { @@ -930,17 +932,19 @@ static int lpm_get(lua_State* L) { } int bytes_read = 0; const char* header_end = NULL; - while (!header_end && bytes_read < sizeof(buffer)) { + while (!header_end && bytes_read < sizeof(buffer) - 1) { buffer_length = lpm_socket_read(s, &buffer[bytes_read], sizeof(buffer) - bytes_read - 1, ssl_ctx); if (buffer_length < 0) { mbedtls_snprintf(ssl_ctx ? 1 : 0, err, sizeof(err), ssl_ctx ? buffer_length : errno, "can't read from socket %s", hostname); goto cleanup; + } else if (buffer_length > 0) { + bytes_read += buffer_length; + buffer[bytes_read] = 0; + header_end = strstr(buffer, "\r\n\r\n"); } - bytes_read += buffer_length; - buffer[bytes_read] = 0; - header_end = strstr(buffer, "\r\n\r\n"); } if (!header_end) { - snprintf(err, sizeof(err), "can't parse response headers for %s%s", hostname, rest); goto cleanup; + snprintf(err, sizeof(err), "can't parse response headers for %s%s: %s", hostname, rest, bytes_read >= sizeof(buffer) - 1 ? "response header buffer length exceeded" : "malformed response"); + goto cleanup; } header_end += 4; const char* protocol_end = strstr(buffer, " "); |