[Spice-devel] [PATCH spice-server 08/11] red-stream: Simplify mechname matching

Christophe Fergeau cfergeau at redhat.com
Tue Dec 19 15:47:55 UTC 2017


On Mon, Dec 11, 2017 at 10:28:05AM +0000, Frediano Ziglio wrote:
> Avoid over complicated matching using quoting and a simple
> strstr operation.

I would explain the trick with sasl_mechlist prefix/suffix in the commit
log.
Looks good otherwise


> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/red-stream.c | 30 +++++++++---------------------
>  1 file changed, 9 insertions(+), 21 deletions(-)
> 
> diff --git a/server/red-stream.c b/server/red-stream.c
> index 55e2c3e0..9e91a3da 100644
> --- a/server/red-stream.c
> +++ b/server/red-stream.c
> @@ -744,6 +744,7 @@ static int auth_sasl_check_ssf(RedSASL *sasl, int *runSSF)
>   * u8-array serverout-strin
>   * u8 continue
>   */
> +#define SASL_MAX_MECHNAME_LEN 100
>  #define SASL_DATA_MAX_LEN (1024 * 1024)
>  
>  RedSaslError red_sasl_handle_auth_step(RedStream *stream, AsyncReadDone read_cb, void *opaque)
> @@ -981,24 +982,11 @@ bool red_sasl_handle_auth_mechname(RedStream *stream, AsyncReadDone read_cb, voi
>      spice_debug("Got client mechname '%s' check against '%s'",
>                 sasl->mechname, sasl->mechlist);
>  
> -    if (strncmp(sasl->mechlist, sasl->mechname, sasl->len) == 0) {
> -        if (sasl->mechlist[sasl->len] != '\0' &&
> -            sasl->mechlist[sasl->len] != ',') {
> -            spice_debug("One %d", sasl->mechlist[sasl->len]);
> -            return false;
> -        }
> -    } else {
> -        char *offset = strstr(sasl->mechlist, sasl->mechname);
> -        spice_debug("Two %p", offset);
> -        if (!offset) {
> -            return false;
> -        }
> -        spice_debug("Two '%s'", offset);
> -        if (offset[-1] != ',' ||
> -            (offset[sasl->len] != '\0'&&
> -             offset[sasl->len] != ',')) {
> -            return false;
> -        }
> +    char quoted_mechname[SASL_MAX_MECHNAME_LEN + 4];
> +    sprintf(quoted_mechname, ",%s,", sasl->mechname);
> +
> +    if (!strstr(sasl->mechlist, quoted_mechname)) {

if (strstr() == NULL) {} ?

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20171219/6cc96270/attachment-0001.sig>


More information about the Spice-devel mailing list