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

Nickolay V. Shmyrev asteriskteam at digium.com
Sun Jul 5 03:09:09 CDT 2020


Nickolay V. Shmyrev 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:

> I think a better way to fix this would be to fix ast_copy_string() to not read past the end of the source buffer for this case.  This then has the potential to fix other places.  There are two places where the function is defined; in include/asterisk/strings.h and utils/extconf.c.

Sorry, I am kind of afraid to change the core function behavior for a simple problem fix. Moreover the semantics of the websocket code is not about string copy anyway, it is more about memory buffer.
 
> Changing the function to the below should do it.
> 
> void ast_copy_string(char *dst, const char *src, size_t size),
> {
> 	if (size) {
> 		while (--size && *src) {
> 			*dst++ = *src++;
> 		}
> 		*dst = '\0';
> 	}
> }

It might be potentially harmful as well. Here it doesn't set \0 byte if size is 0 while it probably should. Speed needs test too.


-- 
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 08:09:09 +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/f8fc328d/attachment.html>


More information about the asterisk-code-review mailing list