endif()
endif()
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -Wvla")
if(CMAKE_VERSION VERSION_LESS "3.1")
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
static int check_auth(struct lws *wsi, struct pss_http *pss) {
if (server->credential == NULL) return AUTH_OK;
- int hdr_length = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_AUTHORIZATION);
- char buf[hdr_length + 1];
+ char buf[256];
int len = lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_HTTP_AUTHORIZATION);
if (len > 0) {
// extract base64 text from authorization header
}
static bool accept_gzip(struct lws *wsi) {
- int hdr_length = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING);
- char buf[hdr_length + 1];
+ char buf[256];
int len = lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_HTTP_ACCEPT_ENCODING);
return len > 0 && strstr(buf, "gzip") != NULL;
}
}
static bool check_host_origin(struct lws *wsi) {
- int origin_length = lws_hdr_total_length(wsi, WSI_TOKEN_ORIGIN);
- char buf[origin_length + 1];
+ char buf[256];
memset(buf, 0, sizeof(buf));
int len = lws_hdr_copy(wsi, buf, (int) sizeof(buf), WSI_TOKEN_ORIGIN);
if (len <= 0) {
sprintf(buf, "%s:%d", address, port);
}
- int host_length = lws_hdr_total_length(wsi, WSI_TOKEN_HOST);
- if (host_length != strlen(buf)) return false;
- char host_buf[host_length + 1];
+ char host_buf[256];
memset(host_buf, 0, sizeof(host_buf));
len = lws_hdr_copy(wsi, host_buf, (int) sizeof(host_buf), WSI_TOKEN_HOST);
static bool spawn_process(struct pss_tty *pss, uint16_t columns, uint16_t rows) {
// append url args to arguments
- char *argv[server->argc + pss->argc + 1];
+ char **argv = xmalloc((server->argc + pss->argc + 1) * sizeof(char *));
int i, n = 0;
for (i = 0; i < server->argc; i++) {
argv[n++] = server->argv[i];
static void wsi_output(struct lws *wsi, pty_buf_t *buf) {
if (buf == NULL) return;
- char message[LWS_PRE + 1 + buf->len];
- char *ptr= &message[LWS_PRE];
+ char *message = xmalloc(LWS_PRE + 1 + buf->len);
+ char *ptr= message + LWS_PRE;
*ptr = OUTPUT;
memcpy(ptr + 1, buf->base, buf->len);
if (lws_write(wsi, (unsigned char *) ptr, n, LWS_WRITE_BINARY) < n) {
lwsl_err("write OUTPUT to WS\n");
}
+
+ free(message);
}
int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in,
uv_thread_join(&process->tid);
#endif
if (process->io != NULL) pty_io_free(process->io);
+ if (process->argv != NULL) free(process->argv);
free(process);
}
}
#if LWS_LIBRARY_VERSION_MAJOR >= 3
+ #define sig_count 2
int sig_nums[] = {SIGINT, SIGTERM};
- int ns = sizeof(sig_nums) / sizeof(sig_nums[0]);
- uv_signal_t signals[ns];
- for (int i = 0; i < ns; i++) {
+ uv_signal_t signals[sig_count];
+ for (int i = 0; i < sig_count; i++) {
uv_signal_init(server->loop, &signals[i]);
uv_signal_start(&signals[i], signal_cb, sig_nums[i]);
}
lws_service(context, 0);
- for (int i = 0; i < ns; i++) {
+ for (int i = 0; i < sig_count; i++) {
uv_signal_stop(&signals[i]);
}
+ #undef sig_count
#else
#if LWS_LIBRARY_VERSION_MAJOR < 2
lws_uv_initloop(context, server->loop, signal_cb, 0);