Browse Source

Shell: Error out on invalid `export' argument

Previously `export =` would crash the shell, make this an error instead.
Ali Mohammad Pur 2 years ago
parent
commit
56b5b78d7b
1 changed files with 4 additions and 0 deletions
  1. 4 0
      Userland/Shell/Builtin.cpp

+ 4 - 0
Userland/Shell/Builtin.cpp

@@ -541,6 +541,10 @@ ErrorOr<int> Shell::builtin_export(Main::Arguments arguments)
 
 
     for (auto& value : vars) {
     for (auto& value : vars) {
         auto parts = value.split_limit('=', 2);
         auto parts = value.split_limit('=', 2);
+        if (parts.is_empty()) {
+            warnln("Shell: Invalid export spec '{}', expected `variable=value' or `variable'", value);
+            return 1;
+        }
 
 
         if (parts.size() == 1) {
         if (parts.size() == 1) {
             auto value = TRY(lookup_local_variable(parts[0]));
             auto value = TRY(lookup_local_variable(parts[0]));