From 1d90c5a855a267bb156d53b6a43bc451a993efd5 Mon Sep 17 00:00:00 2001
From: huj13k4n9 <huj13k4n9@qq.com>
Date: Mon, 29 Apr 2024 12:52:17 +0800
Subject: [PATCH 79/85] Fix 'Failed to execute image pull' on 'name:tag@digest'
 type image name

---
 src/daemon/modules/image/oci/utils_images.c | 6 ++++++
 src/utils/cutils/utils_verify.c             | 3 ++-
 src/utils/cutils/utils_verify.h             | 3 ++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/daemon/modules/image/oci/utils_images.c b/src/daemon/modules/image/oci/utils_images.c
index d94388bd..b4e2a1a8 100644
--- a/src/daemon/modules/image/oci/utils_images.c
+++ b/src/daemon/modules/image/oci/utils_images.c
@@ -207,6 +207,7 @@ int oci_split_image_name(const char *image_name, char **host, char **name, char
     char *tag_digest_pos = NULL;
     char *name_pos = NULL;
     char *tmp_image_name = NULL;
+    char *name_end_pos = NULL;
 
     if (!util_valid_image_name(image_name)) {
         ERROR("Invalid full image name %s", image_name);
@@ -234,6 +235,11 @@ int oci_split_image_name(const char *image_name, char **host, char **name, char
         *name_pos = '\0';
         name_pos++;
         if (name != NULL) {
+            // Need to check if image name contains tag
+            name_end_pos = strchr(name_pos, ':');
+            if (name_end_pos != NULL) {
+                *name_end_pos = '\0';
+            }
             *name = util_strdup_s(name_pos);
         }
         if (host != NULL) {
diff --git a/src/utils/cutils/utils_verify.c b/src/utils/cutils/utils_verify.c
index cd636fff..474e28f0 100644
--- a/src/utils/cutils/utils_verify.c
+++ b/src/utils/cutils/utils_verify.c
@@ -319,6 +319,7 @@ bool util_valid_image_name(const char *name)
         }
     }
 
+    // In name check phase, image name with both tag and digest is also allowed
     if (util_reg_match(__NamePattern, copy)) {
         goto cleanup;
     }
@@ -767,4 +768,4 @@ bool util_valid_search_name(const char *name)
 
     return true;
 }
-#endif
\ No newline at end of file
+#endif
diff --git a/src/utils/cutils/utils_verify.h b/src/utils/cutils/utils_verify.h
index bafd2a82..fc59f6c0 100644
--- a/src/utils/cutils/utils_verify.h
+++ b/src/utils/cutils/utils_verify.h
@@ -32,7 +32,8 @@ extern "C" {
 #define __NamePattern                                                                 \
     "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])"                             \
     "((\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(:[0-9]+)?/)?[a-z0-9]" \
-    "+((([._]|__|[-]*)[a-z0-9]+)+)?((/[a-z0-9]+((([._]|__|[-]*)[a-z0-9]+)+)?)+)?$"
+    "+((([._]|__|[-]*)[a-z0-9]+)+)?((/[a-z0-9]+((([._]|__|[-]*)[a-z0-9]+)+)?)+)?"     \
+    "(:([A-Za-z_0-9][A-Za-z_0-9.-]{0,127}))?$"
 
 #define __DIGESTPattern "@[a-z0-9]+:[a-z0-9]{32,}"
 
-- 
2.34.1

