From: Lukáš Jiřiště Date: Mon, 26 Aug 2024 14:16:51 +0000 (+0200) Subject: Fix tokenization double free X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=374f3c8f838ad2ff7e79ec25097f4bafd42ccfe4;p=42%2Fminishell.git Fix tokenization double free When an unclosed quotes are detected, tokenization fails. This causes double free because the current_token is appended to tokens (because current_token.size > 0) and is freed 4 lines below. The double free happens when the tokens vector frees its memory. --- diff --git a/src/tokenization.c b/src/tokenization.c index 679dbd5..befbd28 100644 --- a/src/tokenization.c +++ b/src/tokenization.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/21 16:34:43 by ljiriste #+# #+# */ -/* Updated: 2024/08/26 12:07:29 by ljiriste ### ########.fr */ +/* Updated: 2024/08/26 16:16:11 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -296,7 +296,7 @@ int tokenize(char **line, t_vec *tokens) else res = ft_vec_append(¤t_token, line[0] + (i++)) != success; } - if (current_token.size > 0) + if (current_token.size > 0 && !res) { ft_vec_append(¤t_token, ""); token.type = (char *)get_token_type(current_token.vec, '\0');