1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00

coverity 160166 readlink doesnt NUL terminate

Ah a real bug... well done coverity, that could have been nasty.

readlink unusually doesn't NUL terminate the result... take care about it.

Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
Andy Green 2016-04-23 07:49:57 +08:00
parent 5dd57a9430
commit 516f388585

View file

@ -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);
}