Am 06.01.2011 10:28, schrieb Oliver Hartkopp: > On 05.01.2011 10:20, Yegor Yefremov wrote: >> fixes the amount of allocated memory for ttypath, so that >> there is place for '\0' >> >> Signed-off-by: Yegor Yefremov <[email protected]> >> >> Index: b/can-utils/slcand.c >> =================================================================== >> --- a/can-utils/slcand.c 2011-01-05 10:13:25.000000000 +0100 >> +++ b/can-utils/slcand.c 2011-01-05 10:13:35.000000000 +0100 >> @@ -235,7 +235,7 @@ >> if (pch == tty) { >> print_usage(argv[0]); >> } >> - ttypath = malloc((strlen(devprefix) + strlen(tty)) * sizeof(char)); >> + ttypath = malloc((strlen(devprefix) + strlen(tty)) + sizeof(char)); > Won't > > ttypath = malloc(strlen(devprefix) + strlen(tty) + 1); > > be more clearly here? Maybe with some comment about the trailing '\0' ??
I'll make some comments. > And what about line 103: > > pidfile = malloc((strlen(pidprefix) +strlen(DAEMON_NAME) + strlen(tty) + > strlen(pidsuffix) + 1) * sizeof(char)); > > Is this the same issue to be fixed? The size of needed memory was calculated correctly (1 for '\0' was added). I have such a premonition that the author if slcand wanted to cover UNICODE strings, but IIRC sizeof(char) is always 1, for UNICODE there is wchar_t or something else. Do I see it right? > I wonder if you can avoid malloc() in both of these cases and use static char > buffers for that. AFAICS you can determine all of the given lengths easily and > the length of the ttyname could (and should!) be limited to e.g. 32 when > checking the commandline parameters. It would be perhaps the best solution, I'll make a new patch. Have just overseen this passage, during messing with line 103. Best regards, Yegor _______________________________________________ Socketcan-core mailing list [email protected] https://lists.berlios.de/mailman/listinfo/socketcan-core
