diff --git a/lib/server.c b/lib/server.c index 2e1969e6..d8096fc7 100644 --- a/lib/server.c +++ b/lib/server.c @@ -233,6 +233,7 @@ int lws_http_serve(struct lws *wsi, char *uri, const char *origin) char path[256], sym[256]; unsigned char *p = (unsigned char *)sym + 32 + LWS_PRE, *start = p; unsigned char *end = p + sizeof(sym) - 32 - LWS_PRE; + size_t len; int n, spin = 0; snprintf(path, sizeof(path) - 1, "%s/%s", origin, uri); @@ -248,10 +249,12 @@ int lws_http_serve(struct lws *wsi, char *uri, const char *origin) lwsl_debug(" %s mode %d\n", path, S_IFMT & st.st_mode); #if !defined(WIN32) if ((S_IFMT & st.st_mode) == S_IFLNK) { - if (readlink(path, sym, sizeof(sym))) { + len = readlink(path, sym, sizeof(sym) - 1); + if (len) { lwsl_err("Failed to read link %s\n", path); goto bail; } + sym[len] = '\0'; lwsl_debug("symlink %s -> %s\n", path, sym); snprintf(path, sizeof(path) - 1, "%s", sym); }