Skip to contentSkip to conversation

libxcmd: add return value check for dynamic memory function

PATCH In review Weifeng Su 3 participants 5 messages Jun 8, 2023 – Jun 13, 2023

lore
Share & tools
lore

Weifeng Su

author
#0 lore raw

PATCH v2 1/1 libxcmd: add return value check for dynamic memory function

The result check was missed and It cause the coredump like:
0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37 0x00005589f3e337d8 in init_commands () at init.c:37
init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112

Add check for realloc function to ignore this coredump and exit with error output

---
Changes since version 1:
- Modify according to review opinions, Add more string

 libxcmd/command.c | 4 ++++
 1 file changed, 4 insertions(+)
libxcmd/command.c +4 -0
index a76d1515..e2603097 100644
@@ -34,6 +34,10 @@ add_command(
 	const cmdinfo_t	*ci)
 {
 	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+	if (!cmdtab) {
+		perror(_("adding libxcmd command"));
+		exit(1);
+	}
 	cmdtab[ncmds - 1] = *ci;
 	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
 }
Signature · 1 line
2.18.0.windows.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Weifeng Su

The result check was missed and It cause the coredump like:
0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37 0x00005589f3e337d8 in init_commands () at init.c:37
init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112

Add check for realloc function to ignore this coredump and exit with error output

Looks good to me,

--D

Quoted 25 lines

---
Changes since version 1:
- Modify according to review opinions, Add more string

 libxcmd/command.c | 4 ++++
 1 file changed, 4 insertions(+)
libxcmd/command.c +4 -0
index a76d1515..e2603097 100644
@@ -34,6 +34,10 @@ add_command(
 	const cmdinfo_t	*ci)
 {
 	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+	if (!cmdtab) {
+		perror(_("adding libxcmd command"));
+		exit(1);
+	}
 	cmdtab[ncmds - 1] = *ci;
 	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
 }
Signature · 1 line
2.18.0.windows.1
author
#2 lore raw

Just ping, Is the merge windown open?

Quoted 42 lines · Darrick J. Wong
Quoted 10 lines · Weifeng Su

The result check was missed and It cause the coredump like:
0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37 0x00005589f3e337d8 in init_commands () at init.c:37
init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112

Add check for realloc function to ignore this coredump and exit with error output

Looks good to me,

--D

Quoted 25 lines

---
Changes since version 1:
- Modify according to review opinions, Add more string

  libxcmd/command.c | 4 ++++
  1 file changed, 4 insertions(+)
libxcmd/command.c +4 -0
index a76d1515..e2603097 100644
@@ -34,6 +34,10 @@ add_command(
  	const cmdinfo_t	*ci)
  {
  	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+	if (!cmdtab) {
+		perror(_("adding libxcmd command"));
+		exit(1);
+	}
  	cmdtab[ncmds - 1] = *ci;
  	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
  }
Signature · 1 line
2.18.0.windows.1
#3 lore raw

[add xfsprogs maintainer to thread]

Quoted 1 line · Weifeng Su

Just ping, Is the merge windown open?

It's never not open for xfsprogs, but mostly it depends on the xfsprogs maintainer (Carlos) deciding to pick up a patch.

--D

Quoted 43 lines · Darrick J. Wong
Quoted 42 lines · Weifeng Su
Quoted 10 lines

The result check was missed and It cause the coredump like:
0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37 0x00005589f3e337d8 in init_commands () at init.c:37
init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112

Add check for realloc function to ignore this coredump and exit with error output

Looks good to me,

--D

Quoted 25 lines

---
Changes since version 1:
- Modify according to review opinions, Add more string

  libxcmd/command.c | 4 ++++
  1 file changed, 4 insertions(+)
libxcmd/command.c +4 -0
index a76d1515..e2603097 100644
@@ -34,6 +34,10 @@ add_command(
  	const cmdinfo_t	*ci)
  {
  	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+	if (!cmdtab) {
+		perror(_("adding libxcmd command"));
+		exit(1);
+	}
  	cmdtab[ncmds - 1] = *ci;
  	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
  }
Signature · 1 line
2.18.0.windows.1
#4 lore raw
Quoted 7 lines · Darrick J. Wong

[add xfsprogs maintainer to thread]

Quoted 1 line · Weifeng Su

Just ping, Is the merge windown open?

It's never not open for xfsprogs, but mostly it depends on the xfsprogs maintainer (Carlos) deciding to pick up a patch.

I'll pull this into for-next on my next batch. Hopefully this week yet.

Signature · 1 line
Carlos
Quoted 46 lines

--D

Quoted 43 lines · Darrick J. Wong
Quoted 42 lines · Weifeng Su
Quoted 10 lines

The result check was missed and It cause the coredump like:
0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37 0x00005589f3e337d8 in init_commands () at init.c:37
init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112

Add check for realloc function to ignore this coredump and exit with error output

Looks good to me,

--D

Quoted 25 lines

---
Changes since version 1:
- Modify according to review opinions, Add more string

  libxcmd/command.c | 4 ++++
  1 file changed, 4 insertions(+)
libxcmd/command.c +4 -1
index a76d1515..e2603097 100644
@@ -34,6 +34,10 @@ add_command(
  	const cmdinfo_t	*ci)
  {
  	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+	if (!cmdtab) {
+		perror(_("adding libxcmd command"));
+		exit(1);
+	}
  	cmdtab[ncmds - 1] = *ci;
  	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
  }
--

2.18.0.windows.1