coverity 169267 - lwsgt strncpy may fill buffer without NUL
authorAndy Green <andy@warmcat.com>
Sun, 28 Aug 2016 01:10:40 +0000 (09:10 +0800)
committerAndy Green <andy@warmcat.com>
Sun, 28 Aug 2016 01:10:40 +0000 (09:10 +0800)
plugins/generic-sessions/protocol_generic_sessions.c

index 9e246b1..7dc31b2 100644 (file)
@@ -418,7 +418,8 @@ callback_generic_sessions(struct lws *wsi, enum lws_callback_reasons reason,
 
                pss->login_session.id[0] = '\0';
                pss->phs.pos = 0;
-               strncpy(pss->onward, (char *)in, sizeof(pss->onward));
+               strncpy(pss->onward, (char *)in, sizeof(pss->onward) - 1);
+               pss->onward[sizeof(pss->onward) - 1] = '\0';
 
                if (!strcmp((const char *)in, "/lwsgs-forgot")) {
                        lwsgs_handler_forgot(vhd, wsi, pss);
@@ -512,9 +513,10 @@ callback_generic_sessions(struct lws *wsi, enum lws_callback_reasons reason,
                                 sqlite3_errmsg(vhd->pdb));
                        break;
                }
-               strncpy(sinfo->username, u.username, sizeof(sinfo->username));
-               strncpy(sinfo->email, u.email, sizeof(sinfo->email));
-               strncpy(sinfo->session, sid.id, sizeof(sinfo->session));
+               strncpy(sinfo->username, u.username, sizeof(sinfo->username) - 1);
+               sinfo->username[sizeof(sinfo->username) - 1] = '\0';
+               strncpy(sinfo->email, u.email, sizeof(sinfo->email) - 1);
+               strncpy(sinfo->session, sid.id, sizeof(sinfo->session) - 1);
                sinfo->mask = lwsgs_get_auth_level(vhd, username);
                lws_get_peer_simple(wsi, sinfo->ip, sizeof(sinfo->ip));
        }