perf tools: Incorrect use of snprintf results in SEGV
[firefly-linux-kernel-4.4.55.git] / tools / perf / util / sort.c
index f44fa541d56e67c6bb6c976e78123e99657ffbee..0ffbc8e5b4b5ef5a054ca3eab4a331c2c6c9f7be 100644 (file)
@@ -122,6 +122,9 @@ static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...)
                }
        }
        va_end(ap);
+
+       if (n >= (int)size)
+               return size - 1;
        return n;
 }