在 shell 中粘贴错误会导致 CPU 负载非常高,然后失控



今天我错误地将一个字符串粘贴到我的 linux shell 中,之后 CPU 负载非常高,然后它失控

了我的环境是 CentOS 6.5,我粘贴的字符串是 json 格式的请求日志:

[{"timestamp":1487240104178,"info":{"method":"GET","path":"/APIService/v1/refreshSession","headers":{"request":{"user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","host":"172.22.3.12:8122","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}},{"timestamp":1487240077403,"info":{"method":"GET","path":"/APIService/v1/refreshSession","headers":{"request":{"user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","host":"172.22.3.12:8122","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}},{"timestamp":1487240075185,"info":{"method":"GET","path":"/APIService/v1/refreshSession","headers":{"request":{"user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","host":"172.22.3.12:8122","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}},{"timestamp":1487240050994,"info":{"method":"GET","path":"/APIService/v1/refreshSession","headers":{"request":{"user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","host":"172.22.3.12:8122","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}},{"timestamp":1487240037110,"info":{"method":"GET","path":"/APIService/v1/refreshSession","headers":{"request":{"user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","host":"172.22.3.12:8122","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}},{"timestamp":1487240025956,"info":{"method":"GET","path":"/APIService/v1/refreshSession","headers":{"request":{"user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","host":"172.22.3.12:8122","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}},{"timestamp":1487239999461,"info":{"method":"GET","path":"/APIService/v1/refreshSession","headers":{"request":{"host":"172.22.1.15","remote_addr":"172.22.1.15","x-real-ip":"172.22.1.15","x-forwarded-for":"172.22.1.15","user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}},{"timestamp":1487239998662,"info":{"method":"GET","path":"/APIService/v1/refreshSession","headers":{"request":{"host":"172.22.1.15","remote_addr":"172.22.1.15","x-real-ip":"172.22.1.15","x-forwarded-for":"172.22.1.15","user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}},{"timestamp":1487239889129,"info":{"method":"GET","path":"/APIservice/v1/refreshSession","headers":{"request":{"host":"172.22.1.15","remote_addr":"172.22.1.15","x-real-ip":"172.22.1.15","x-forwarded-for":"172.22.1.15","user-agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2","accept":"*/*"},"response":{"X-Application-Context":"application:8122","status":"404"}}}}][root@web-01 conf]

重新启动后,计算机正常。

谁能告诉我发生了什么,为什么该字符串导致如此高的 CPU 负载?

关于字符串末尾的[root@web-01 conf]。 这是外壳提示吗? 您是否以根用户身份登录到外壳? 我拍你的手腕! 别这样。

我不确定,但我相信 shell 正试图将字符串扩展为命令,并且由于字符串*/*多次出现而碰壁。 当 bash 看到一个形式为{a,b,c,*/*}的字符串时,它会尝试将其扩展为字符串a b c ...其中...是 glob*/*的扩展。 当它看到嵌套括号扩展时,它也会扩展它们。 我认为你已经发生了组合爆炸。

最新更新