openocd: fix SPDX tag format for files .c
[fw/openocd] / src / server / telnet_server.c
index 4fc71f384e26a693e9bc0dc5d538811da732065d..938bc5b0624972e52cf207326fbac5d6a82a85ae 100644 (file)
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
@@ -7,19 +9,6 @@
  *                                                                         *
  *   Copyright (C) 2008 by Spencer Oliver                                  *
  *   spen@spen-soft.co.uk                                                  *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -615,7 +604,11 @@ static void telnet_auto_complete(struct connection *connection)
        while ((usr_cmd_pos < t_con->line_cursor) && isspace(t_con->line[usr_cmd_pos]))
                usr_cmd_pos++;
 
-       /* user command length */
+       /* check user command length */
+       if (t_con->line_cursor < usr_cmd_pos) {
+               telnet_bell(connection);
+               return;
+       }
        size_t usr_cmd_len = t_con->line_cursor - usr_cmd_pos;
 
        /* optimize multiple spaces in the user command,