Browse Source

Avoid read-past-end of string in get_bold_admin_title (#1499)

Michael Jones 1 year ago
parent
commit
e8fa2f666a
1 changed files with 3 additions and 2 deletions
  1. 3 2
      src/apps/relay/turn_admin_server.c

+ 3 - 2
src/apps/relay/turn_admin_server.c

@@ -1533,11 +1533,12 @@ static ioa_socket_handle current_socket = NULL;
 
 static char *get_bold_admin_title(void) {
   static char sbat[1025];
-  strncpy(sbat, __bold_admin_title, sizeof(sbat));
+  strncpy(sbat, __bold_admin_title, sizeof(sbat) - 1);
+  sbat[sizeof(sbat) - 1] = '\0';
 
   if (current_socket && current_socket->special_session) {
     struct admin_session *as = (struct admin_session *)current_socket->special_session;
-    if (as->as_ok) {
+    if (as && as->as_ok) {
       if (as->as_login[0]) {
         char *dst = sbat + strlen(sbat);
         snprintf(dst, ADMIN_USER_MAX_LENGTH * 2 + 2, " admin user: <b><i>%s</i></b><br>\r\n", as->as_login);