Repository: theseus-os/Theseus (language: rust)

Issue:
[applications/shell] Shell panics in Shell::eval_cmdline().
https://github.com/theseus-os/Theseus/blob/585ab93e0505f9ac8385764ed4353c8271b80d83/applications/shell/src/lib.rs#L688-L721

```Rust
let command = args.remove(0); 
```
This panics if args.len()==0.
So shell input(cmdline) like
```
|
```
and

``` 
X | 
```
  cause panic at args.remove().

I think the priority for this is low for now.
So I just leave an issue here.


Discussion / hints:
thanks for reporting this @yingwei9! We haven't devoted a lot of time to the `shell` since it will be eventually removed in favor of a proper terminal emulator, but it'd still be good to fix this in the meantime.

If you'd like to submit a fix for this, that'd be greatly appreciated; I'd be happy to review a PR. Otherwise we can leave it open and see if anyone wants to tackle it.

Fix patch:
diff --git a/applications/shell/src/lib.rs b/applications/shell/src/lib.rs
index 1afd2c90f8..05dff7ad4e 100644
--- a/applications/shell/src/lib.rs
+++ b/applications/shell/src/lib.rs
@@ -681,9 +681,14 @@ impl Shell {
     /// all tasks that have already been spawned will be killed immeidately before returning error.
     fn eval_cmdline(&mut self) -> Result<Vec<JoinableTaskRef>, AppErr> {
 
-        let cmdline = self.cmdline.clone();
+        let cmdline = self.cmdline.trim().to_string();
         let mut task_refs = Vec::new();
 
+        // If the command line is empty or starts with '|', return 'AppErr'
+        if cmdline.is_empty() || cmdline.starts_with('|') {
+            return Err(AppErr::NotFound(cmdline))
+        }
+
         for single_task_cmd in cmdline.split('|') {
             let mut args: Vec<String> = single_task_cmd.split_whitespace().map(|s| s.to_string()).collect();
             let command = args.remove(0);
@@ -791,7 +796,15 @@ impl Shell {
             },
             Err(err) => {
                 let err_msg = match err {
-                    AppErr::NotFound(command) => format!("{:?} command not found.\n", command),
+                    AppErr::NotFound(command) => {
+                        // No need to return err if command is empty
+                        if command.trim().is_empty() {
+                            String::new()
+                        }
+                        else {
+                            format!("{:?} command not found.\n", command)
+                        }
+                    },
                     AppErr::NamespaceErr      => format!("Failed to find directory of application executables.\n"),
                     AppErr::SpawnErr(e)       => format!("Failed to spawn new task to run command. Error: {}.\n", e),
                 };


Test patch: