Skip to contentSkip to conversation

erofs-utils: lib: fix potential NULL pointer dereference in docker_config.c

PATCH Superseded Sri Lasya 2 participants 3 messages Mar 15 – Mar 16

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sri Lasya

author
#0 lore raw

PATCH 1/1 erofs-utils: lib: fix potential NULL pointer dereference in docker_config.c

---
 lib/remotes/docker_config.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/remotes/docker_config.c +2 -1
index 00db1bb..b346ee8 100644
@@ -38,7 +38,6 @@ static char *docker_config_path(void)
 {
 	const char *dir;
 	char *path = NULL;
-
 	dir = getenv("DOCKER_CONFIG");
 	if (dir) {
 		if (!*dir)
@@ -203,6 +202,8 @@ int erofs_docker_config_lookup(const char *registry,
 		}
 
 		entry = json_object_iter_peek_value(&it);
+                if (!entry)
+			continue;
 		if (json_object_object_get_ex(entry, "auth", &auth_field)) {
 			b64 = json_object_get_string(auth_field);
 			if (b64 && *b64) {
Signature · 1 line
2.43.0
#1 lore raw
Quoted 18 lines · Sri Lasya
---
  lib/remotes/docker_config.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
lib/remotes/docker_config.c +0 -1
index 00db1bb..b346ee8 100644
@@ -38,7 +38,6 @@ static char *docker_config_path(void)
  {
  	const char *dir;
  	char *path = NULL;
-
  	dir = getenv("DOCKER_CONFIG");
  	if (dir) {
  		if (!*dir)

lib/remotes/docker_config.c int erofs_docker_config_lookup(const char *registry, · line 206

Quoted 5 lines
lib/remotes/docker_config.c +2 -0
@@ -203,6 +202,8 @@ int erofs_docker_config_lookup(const char *registry,
  		}
 
  		entry = json_object_iter_peek_value(&it);
+                if (!entry)
+			continue;

The patch format is broken, also Chengyu could you review it?

Thanks,
Gao Xiang

Quoted 3 lines
lib/remotes/docker_config.c +0 -0
  		if (json_object_object_get_ex(entry, "auth", &auth_field)) {
  			b64 = json_object_get_string(auth_field);
  			if (b64 && *b64) {
#2 lore raw

Hi Gao,

Thank you for the feedback. I apologize for the formatting issues in the first version.

I have sent a [PATCH v2] via git send-email to ensure the tabs and formatting are preserved correctly. In the second version, I also added an iterator increment to prevent a potential infinite loop when an entry is NULL.

Hi Chengyu, please review the V2 version instead.

Best regards,
Sri Lasya

Quoted 37 lines · Gao Xiang
Quoted 18 lines · Sri Lasya
---
  lib/remotes/docker_config.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
lib/remotes/docker_config.c +0 -1
index 00db1bb..b346ee8 100644
@@ -38,7 +38,6 @@ static char *docker_config_path(void)
  {
      const char *dir;
      char *path = NULL;
-
      dir = getenv("DOCKER_CONFIG");
      if (dir) {
              if (!*dir)

lib/remotes/docker_config.c int erofs_docker_config_lookup(const char *registry, · line 206

Quoted 5 lines
lib/remotes/docker_config.c +2 -0
@@ -203,6 +202,8 @@ int erofs_docker_config_lookup(const char *registry,
              }
 
              entry = json_object_iter_peek_value(&it);
+                if (!entry)
+                     continue;

The patch format is broken, also Chengyu could you review it?

Thanks,
Gao Xiang

Quoted 3 lines
lib/remotes/docker_config.c +0 -0
              if (json_object_object_get_ex(entry, "auth", &auth_field)) {
                      b64 = json_object_get_string(auth_field);
                      if (b64 && *b64) {