[Asterisk-code-review] res_http_websocket: Add trailing zero for text strings (asterisk[master])

Richard Mudgett asteriskteam at digium.com
Sun Jul 5 09:05:52 CDT 2020


Richard Mudgett has posted comments on this change. ( https://gerrit.asterisk.org/c/asterisk/+/14626 )

Change subject: res_http_websocket: Add trailing zero for text strings
......................................................................


Patch Set 1:

> Patch Set 1:
> 
> Maybe, change like this instead should work (a simple reorder of checks in existing code):
> 
> AST_INLINE_API(
> void ast_copy_string(char *dst, const char *src, size_t size),
> {
> 	while (size && *src) {
> 		*dst++ = *src++;
> 		size--;
> 	}
> 	if (__builtin_expect(!size, 0))
> 		dst--;
> 	*dst = '\0';
> }
> )

You cannot set anything in the buffer if the size is zero.  The caller has told us there is no size to the passed in buffer so there is no room for the string terminator.  The code I have posted will prevent the unnecessary buffer read valgrind found because the code will not copy the string terminator that may or may not be there.  The code I posted is simpler.


-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14626
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ib4a75cffeb1eb8cf01136ef30306bd623e531a2a
Gerrit-Change-Number: 14626
Gerrit-PatchSet: 1
Gerrit-Owner: Nickolay V. Shmyrev <nshmyrev at alphacephei.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
Gerrit-Comment-Date: Sun, 05 Jul 2020 14:05:52 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200705/a018131a/attachment.html>


More information about the asterisk-code-review mailing list