diff --git a/tools/command.c b/tools/command.c
index 50791b1..3270b26 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -1375,7 +1375,7 @@ static int _copy_line(char *line, int max_line, int *position)
 
 	memset(line, 0, max_line);
 
-	while (1) {
+	while ( p < strlen(_command_input) ) {
 		line[i] = _command_input[p];
 		i++;
 		p++;
