[PATCH 1/1] rpcdebug: fix memory allocation size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Memory isn't allocated enough to hold the null terminator.

Valgring complains about invalid memory access:

[aglo@localhost rpcdebug]$ valgrind ./rpcdebug
==222602== Memcheck, a memory error detector
==222602== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==222602== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==222602== Command: ./rpcdebug
==222602==
==222602== Invalid write of size 1
==222602==    at 0x4871218: strcpy (vg_replace_strmem.c:564)
==222602==    by 0x400CA3: main (rpcdebug.c:62)
==222602==  Address 0x4a89048 is 0 bytes after a block of size 8 alloc'd
==222602==    at 0x4868388: malloc (vg_replace_malloc.c:446)
==222602==    by 0x400C77: main (rpcdebug.c:57)
==222602==
==222602== Invalid read of size 1
==222602==    at 0x48710E4: __GI_strlen (vg_replace_strmem.c:506)
==222602==    by 0x492FA7F: __vfprintf_internal (vfprintf-internal.c:1647)
==222602==    by 0x49302F3: buffered_vfprintf (vfprintf-internal.c:2296)
==222602==    by 0x492F21F: __vfprintf_internal (vfprintf-internal.c:1377)
==222602==    by 0x491BC93: fprintf (fprintf.c:32)
==222602==    by 0x40103F: main (rpcdebug.c:100)
==222602==  Address 0x4a89048 is 0 bytes after a block of size 8 alloc'd
==222602==    at 0x4868388: malloc (vg_replace_malloc.c:446)

Signed-off-by: Olga Kornievskaia <okorniev@xxxxxxxxxx>
---
 tools/rpcdebug/rpcdebug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/rpcdebug/rpcdebug.c b/tools/rpcdebug/rpcdebug.c
index ec05179e..1f935223 100644
--- a/tools/rpcdebug/rpcdebug.c
+++ b/tools/rpcdebug/rpcdebug.c
@@ -54,7 +54,7 @@ main(int argc, char **argv)
 	char *		module = NULL;
 	int		c;
 
-	cdename = malloc(strlen(basename(argv[0])));
+	cdename = malloc(strlen(basename(argv[0])) + 1);
 	if (cdename == NULL) {
 	  fprintf(stderr, "failed in malloc\n");
 	  exit(1);
-- 
2.43.5





[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux