Browse Source

AMBARI-581. Strip carriage-return related control-chars from hosts files (Contributed by Jaimin Jetly)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1354780 13f79535-47bb-0310-9956-ffa450edef68
Hitesh Shah 13 years ago
parent
commit
80731ec2a6
3 changed files with 12 additions and 0 deletions
  1. 3 0
      CHANGES.txt
  2. 2 0
      hmc/php/frontend/addNodes.php
  3. 7 0
      hmc/php/util/util.php

+ 3 - 0
CHANGES.txt

@@ -6,6 +6,9 @@ characters wide.
 
 Release 1.0.0 - unreleased
 
+  AMBARI-581. Strip carriage-return related control-chars from hosts files
+  (Jaimin Jetly via hitesh)
+
   AMBARI-582. Update the installation guide - monitoring dashboard install
   instructions (yusaku) 
 

+ 2 - 0
hmc/php/frontend/addNodes.php

@@ -75,6 +75,8 @@ if (move_uploaded_file($_FILES['clusterHostsFile']['tmp_name'], $hostsFileDestin
     //echo "Possible file upload attack!\n";
 }
 
+removeCarriageReturn($hostsFileDestination);
+
 header("Content-type: application/json");
 
 // Validate that there are no nodes that are already in use in case of addNodesWizard

+ 7 - 0
hmc/php/util/util.php

@@ -51,4 +51,11 @@ function convertToLowerCase($hosts) {
   return $result;
 }
 
+function removeCarriageReturn($hostsFileDestination) {
+  exec("sed -i -e 's/\r//g' ". $hostsFileDestination, $output, $retVal);
+  if($retVal != 0) {
+    $logger->log_error("shell command exec() removing '\r' from ". $hostsFileDestination . " file failed");
+  }
+}
+
 ?>