【问题标题】:Magento 1.7.2 SECURITY PATCH ERROR Via SSHMagento 1.7.2 安全补丁错误通过 SSH
【发布时间】:2023-03-09 08:01:02
【问题描述】:

按照指示逐字逐句...

Please upload the patch into your Magento root directory and run the appropriate SSH command:
For patch files with the file extension .sh:
sh patch_file_name.sh
Example: sh PATCH_SUPEE-1868_CE_1.7.0.2_v1.sh

我已上传补丁文件 PATCH_SUPEE-2518_CE_1.5.1.0-1.7.0.2_v1.sh

到magento根目录(public_html/)并在执行时收到此错误。

root@atlas [/home/public_html/]# sh PATCH_SUPEE-2518_CE_1.5.1.0-1.7.0.2_v1.sh
: command not found_1.5.1.0-1.7.0.2_v1.sh: line 7:
'ATCH_SUPEE-2518_CE_1.5.1.0-1.7.0.2_v1.sh: line 9: syntax error near unexpected token `{
'ATCH_SUPEE-2518_CE_1.5.1.0-1.7.0.2_v1.sh: line 9: `_check_installed_tools() {

.sh 补丁文件中的第 9 行是

_check_installed_tools() {
local missed=""

until [ -z "$1" ]; do
    type -t $1 >/dev/null 2>/dev/null
    if (( $? != 0 )); then
        missed="$missed $1"
    fi
    shift
done

echo $missed

我在此文件中看不到错误,也不了解导致此文件失败的原因。其他人有这个问题,或者知道什么吗?

整个 .sh 文件内容

#!/bin/bash
# Patch apllying tool template
# v0.1.2
# (c) Copyright 2013. Magento Inc.
#
# DO NOT CHANGE ANY LINE IN THIS FILE.

# 1. Check required system tools
_check_installed_tools() {
    local missed=""

    until [ -z "$1" ]; do
        type -t $1 >/dev/null 2>/dev/null
        if (( $? != 0 )); then
            missed="$missed $1"
        fi
        shift
    done

    echo $missed
}

REQUIRED_UTILS='sed patch'
MISSED_REQUIRED_TOOLS=`_check_installed_tools $REQUIRED_UTILS`
if (( `echo $MISSED_REQUIRED_TOOLS | wc -w` > 0 ));
then
    echo -e "Error! Some required system tools, that are utilized in this sh script, are not installed:\nTool(s) \"$MISSED_REQUIRED_TOOLS\" is(are) missed, please install it(them)."
    exit 1
fi

# 2. Determine bin path for system tools
CAT_BIN=`which cat`
PATCH_BIN=`which patch`
SED_BIN=`which sed`
PWD_BIN=`which pwd`
BASENAME_BIN=`which basename`

BASE_NAME=`$BASENAME_BIN "$0"`

# 3. Help menu
if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]
then
    $CAT_BIN << EOFH
Usage: sh $BASE_NAME [--help] [-R|--revert] [--list]
Apply embedded patch.

-R, --revert    Revert previously applied embedded patch
--list          Show list of applied patches
--help          Show this help message
EOFH
    exit 0
fi

# 4. Get "revert" flag and "list applied patches" flag
REVERT_FLAG=
SHOW_APPLIED_LIST=0
if [ "$1" = "-R" -o "$1" = "--revert" ]
then
    REVERT_FLAG=-R
fi
if [ "$1" = "--list" ]
then
    SHOW_APPLIED_LIST=1
fi

# 5. File pathes
CURRENT_DIR=`$PWD_BIN`/
APP_ETC_DIR=`echo "$CURRENT_DIR""app/etc/"`
APPLIED_PATCHES_LIST_FILE=`echo "$APP_ETC_DIR""applied.patches.list"`

# 6. Show applied patches list if requested
if [ "$SHOW_APPLIED_LIST" -eq 1 ] ; then
    echo -e "Applied/reverted patches list:"
    if [ -e "$APPLIED_PATCHES_LIST_FILE" ]
    then
        if [ ! -r "$APPLIED_PATCHES_LIST_FILE" ]
        then
            echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be readable so applied patches list can be shown."
            exit 1
        else
            $SED_BIN -n "/SUP-\|SUPEE-/p" $APPLIED_PATCHES_LIST_FILE
        fi
    else
        echo "<empty>"
    fi
    exit 0
fi

# 7. Check applied patches track file and its directory
_check_files() {
    if [ ! -e "$APP_ETC_DIR" ]
    then
        echo "ERROR: \"$APP_ETC_DIR\" must exist for proper tool work."
        exit 1
    fi

    if [ ! -w "$APP_ETC_DIR" ]
    then
        echo "ERROR: \"$APP_ETC_DIR\" must be writeable for proper tool work."
        exit 1
    fi

    if [ -e "$APPLIED_PATCHES_LIST_FILE" ]
    then
        if [ ! -w "$APPLIED_PATCHES_LIST_FILE" ]
        then
            echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be writeable for proper tool work."
            exit 1
        fi
    fi
}

_check_files

# 8. Apply/revert patch
# Note: there is no need to check files permissions for files to be patched.
# "patch" tool will not modify any file if there is not enough permissions for all files to be modified.
# Get start points for additional information and patch data
SKIP_LINES=$((`$SED_BIN -n "/^__PATCHFILE_FOLLOWS__$/=" "$CURRENT_DIR""$BASE_NAME"` + 1))
ADDITIONAL_INFO_LINE=$(($SKIP_LINES - 3))p

_apply_revert_patch() {
    DRY_RUN_FLAG=
    if [ "$1" = "dry-run" ]
    then
        DRY_RUN_FLAG=" --dry-run"
        echo "Checking if patch can be applied/reverted successfully..."
    fi
    PATCH_APPLY_REVERT_RESULT=`$SED_BIN -e '1,/^__PATCHFILE_FOLLOWS__$/d' "$CURRENT_DIR""$BASE_NAME" | $PATCH_BIN $DRY_RUN_FLAG $REVERT_FLAG -p0`
    PATCH_APPLY_REVERT_STATUS=$?
    if [ $PATCH_APPLY_REVERT_STATUS -eq 1 ] ; then
        echo -e "ERROR: Patch can't be applied/reverted successfully.\n\n$PATCH_APPLY_REVERT_RESULT"
        exit 1
    fi
    if [ $PATCH_APPLY_REVERT_STATUS -eq 2 ] ; then
        echo -e "ERROR: Patch can't be applied/reverted successfully."
        exit 2
    fi
}

REVERTED_PATCH_MARK=
if [ -n "$REVERT_FLAG" ]
then
    REVERTED_PATCH_MARK=" | REVERTED"
fi

_apply_revert_patch dry-run
_apply_revert_patch

# 9. Track patch applying result
echo "Patch was applied/reverted successfully."
ADDITIONAL_INFO=`$SED_BIN -n ""$ADDITIONAL_INFO_LINE"" "$CURRENT_DIR""$BASE_NAME"`
APPLIED_REVERTED_ON_DATE=`date -u +"%F %T UTC"`
APPLIED_REVERTED_PATCH_INFO=`echo -n "$APPLIED_REVERTED_ON_DATE"" | ""$ADDITIONAL_INFO""$REVERTED_PATCH_MARK"`
echo -e "$APPLIED_REVERTED_PATCH_INFO\n$PATCH_APPLY_REVERT_RESULT\n\n" >> "$APPLIED_PATCHES_LIST_FILE"

exit 0


SUPEE-2518 | CE_1.7.0.2 | v1 | e6f2d2354843b1ca69988a44de1761ce180e746c | Thu Nov 21 12:44:53 2013 +0200 | v1.7.0.2..SUPEE-2518

__PATCHFILE_FOLLOWS__
diff --git app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
index 9e8d6be..b106d09 100644
--- app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
+++ app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
@@ -197,11 +197,11 @@ class Mage_Cms_Helper_Wysiwyg_Images extends Mage_Core_Helper_Abstract
     public function getCurrentPath()
     {
         if (!$this->_currentPath) {
-            $currentPath = $this->getStorageRoot();
-            $path = $this->_getRequest()->getParam($this->getTreeNodeName());
-            if ($path) {
-                $path = $this->convertIdToPath($path);
-                if (is_dir($path)) {
+            $currentPath = realpath($this->getStorageRoot());
+            $node = $this->_getRequest()->getParam($this->getTreeNodeName());
+            if ($node) {
+                $path = realpath($this->convertIdToPath($node));
+                if (is_dir($path) && false !== stripos($path, $currentPath)) {
                     $currentPath = $path;
                 }
             }

【问题讨论】:

  • 补丁文件的链接可以帮助人们调试它。
  • 艾伦,我已经将文件内容更新为问题,谢谢先生!
  • 可能感兴趣——您可能需要使用 bash 而不是 sh 运行该补丁。 magento.stackexchange.com/questions/13644/…

标签: magento ssh magento-1.7 patch


【解决方案1】:

我遇到了同样的错误:

root@www01:/www/sites/REDACTED/files/html# sh PATCH_SUPEE-2518_EE_1.10.1.0-1.13.0.2_v1.sh
: not found-2518_EE_1.10.1.0-1.13.0.2_v1.sh: 7:
: not found-2518_EE_1.10.1.0-1.13.0.2_v1.sh: 11:
PATCH_SUPEE-2518_EE_1.10.1.0-1.13.0.2_v1.sh: 168: Syntax error: "(" unexpected (expecting "then")

当我在 vim 中检查它时,我看到它是在 DOS 中编码的。运行dos2unix,补丁安装成功:

root@www01:/www/sites/REDACTED/files/html# dos2unix PATCH_SUPEE-2518_EE_1.10.1.0-1.13.0.2_v1.sh
dos2unix: converting file PATCH_SUPEE-2518_EE_1.10.1.0-1.13.0.2_v1.sh to UNIX format ...
root@www01:/www/sites/REDACTED/files/html# bash PATCH_SUPEE-2518_EE_1.10.1.0-1.13.0.2_v1.sh
Checking if patch can be applied/reverted successfully...
Patch was applied/reverted successfully.

【讨论】:

    【解决方案2】:

    我遇到了同样的错误。我通过安装“补丁”来修复它。奇怪的是,我来到这个线程寻求答案并尝试了所有这些,除了@hadis 建议。我通过尝试运行“yum patch_name.sh”误解了他的解决方案

    我最终查看了文件,之后他的解决方案相当明显。安装“补丁”后,再次执行脚本,瞧! :)

    yum install patch
    
    sh PATCH_SUPEE-1868_CE_1.7.0.2_v1.sh
    

    【讨论】:

      【解决方案3】:

      尝试创建新的文本文件,例如 mypatch.patch 并将补丁中的差异复制到它

      diff --git app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
      index 9e8d6be..b106d09 100644
      --- app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
      +++ app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
      @@ -197,11 +197,11 @@ class Mage_Cms_Helper_Wysiwyg_Images extends Mage_Core_Helper_Abstract
           public function getCurrentPath()
           {
               if (!$this->_currentPath) {
      -            $currentPath = $this->getStorageRoot();
      -            $path = $this->_getRequest()->getParam($this->getTreeNodeName());
      -            if ($path) {
      -                $path = $this->convertIdToPath($path);
      -                if (is_dir($path)) {
      +            $currentPath = realpath($this->getStorageRoot());
      +            $node = $this->_getRequest()->getParam($this->getTreeNodeName());
      +            if ($node) {
      +                $path = realpath($this->convertIdToPath($node));
      +                if (is_dir($path) && false !== stripos($path, $currentPath)) {
                           $currentPath = $path;
                       }
                   }
      

      然后将其复制到您商店的根目录并执行:

      patch -p0 < mypatch.patch
      

      或者可能会尝试改变

      _check_installed_tools() {
      

      到

      function _check_installed_tools {
      

      在基本脚本中

      【讨论】:

        【解决方案4】:

        你必须安装补丁 尝试这个: 百胜安装补丁

        【讨论】:

        • 文档...示例?
        【解决方案5】:

        去magento下载补丁站点。当您单击 magento 站点上的下载按钮时,它将打开一个带有补丁代码的新站点。右键单击它并选择查看源代码(使用 chrome)

        查看源代码:http://www.magentocommerce.com/index.php/getmagento/ce_patches/PATCH_SUPEE-2629_EE_1.12.0.0_v1.sh

        然后再次右键单击并将文件保存为例如PATCH_SUPEE-2629_EE_1.12.0.0_v1.sh。 最后将文件移动到您的magento安装的根目录并尝试再次应用补丁。对我来说它有效。

        【讨论】:

          【解决方案6】:

          我发现当补丁文件(不是正在修补的文件)的行尾与运行它的系统不匹配时会发生此错误。

          例如:

          • 您正在 Linux 上运行
          • 补丁文件有 Windows 行结尾

          然后您需要检查正在修补的文件是否也有运行它的系统的行尾

          另见Error patching Magento 1.7.1 Hunk #1 Failed at

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-02-04
            • 1970-01-01
            • 2017-11-11
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-02-19
            • 1970-01-01
            相关资源
            最近更新 更多