Fix tokenization double free
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 26 Aug 2024 14:16:51 +0000 (16:16 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 26 Aug 2024 14:16:51 +0000 (16:16 +0200)
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.

src/tokenization.c

index 679dbd5d284da02218dc75eda1dcc9a012ecd358..befbd2816d89a095e890ec6ea991a345639aa7e7 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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(&current_token, line[0] + (i++)) != success;
        }
-       if (current_token.size > 0)
+       if (current_token.size > 0 && !res)
        {
                ft_vec_append(&current_token, "");
                token.type = (char *)get_token_type(current_token.vec, '\0');