diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index e20dd626bcf257edd0b3294a43b33bf77a0b7f11..d79215bf4ad2538d10eaeee0ef95fb52f80f3dd8 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -62,6 +62,8 @@ static char *parse_link_name(const char **buf, void *log_ctx)
     (*buf)++;
 
     name = av_get_token(buf, "]");
+    if (!name)
+        goto fail;
 
     if (!name[0]) {
         av_log(log_ctx, AV_LOG_ERROR,