X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-token.c;h=4e8b5d4df23482ca6dab12cc6589af1bd8040f70;hb=65353dce81a629e042800bb7b86fcd869a76727e;hp=f6f5eb7360724af78de0d1c61f5ce14abcbf7511;hpb=d8aff62647736c3f17ff15989ec9f90b48efe1c4;p=src%2Fapp-framework-binder.git diff --git a/src/afb-token.c b/src/afb-token.c index f6f5eb73..4e8b5d4d 100644 --- a/src/afb-token.c +++ b/src/afb-token.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2019 "IoT.bzh" + * Copyright (C) 2015-2020 "IoT.bzh" * Author "Fulup Ar Foll" * Author: José Bollo * @@ -86,7 +86,7 @@ int afb_token_get(struct afb_token **token, const char *tokenstring) /* search the token */ tok = tokenset.first; - while (tok && memcmp(tokenstring, tok->text, length)) + while (tok && (memcmp(tokenstring, tok->text, length) || tokenstring[length])) tok = tok->next; /* search done */ @@ -96,7 +96,7 @@ int afb_token_get(struct afb_token **token, const char *tokenstring) rc = 0; } else { /* not found, create */ - tok = malloc(length + sizeof *tok); + tok = malloc(length + 1 + sizeof *tok); if (!tok) /* creation failed */ rc = -ENOMEM; @@ -106,7 +106,7 @@ int afb_token_get(struct afb_token **token, const char *tokenstring) tokenset.first = tok; tok->id = tokenset.idgen; tok->refcount = 1; - memcpy(tok->text, tokenstring, length); + memcpy(tok->text, tokenstring, length + 1); rc = 0; } } @@ -140,6 +140,7 @@ void afb_token_unref(struct afb_token *token) pthread_mutex_lock(&tokenset.mutex); pt = &tokenset.first; while (*pt && *pt != token) + pt = &(*pt)->next; if (*pt) *pt = token->next; pthread_mutex_unlock(&tokenset.mutex);