[gnutls-devel] GnuTLS | index should check before use (!1771)

Read-only notification of GnuTLS library development activities gnutls-devel at lists.gnutls.org
Wed Aug 23 09:00:40 CEST 2023




Daiki Ueno started a new discussion on src/srptool.c: https://gitlab.com/gnutls/gnutls/-/merge_requests/1771#note_1524082559

>  	while (fgets(line, sizeof(line), fp) != NULL) {
>  		/* move to first ':' */
>  		i = 0;
> -		while ((line[i] != ':') && (line[i] != '\0') &&
> -		       (i < sizeof(line))) {
> +		while ((i < sizeof(line)) && (line[i] != ':') && (line[i] != '\0')) {
>  			i++;
>  		}

I wonder why the original code is written this way; isn't it equivalent to:
```c
/* parse a line in the form: <username>:...:<index> */
size_t len = strlen(username);
if (strncmp(username, line, len) == 0 && line[len] == ':') {
  ...
}
```
?

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/-/merge_requests/1771#note_1524082559
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20230823/ff589e8c/attachment-0001.html>


More information about the Gnutls-devel mailing list