Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Have zero size length in filter logic be full string

As strings in trace events may not have a nul terminating character, the
filter string compares use the defined string length for the field for the
compares.

The trace_marker records data slightly different than do normal events. It's
size is zero, meaning that the string is the rest of the array, and that the
string also ends with '\0'.

If the size is zero, assume that the string is nul terminated and read the
string in question as is.

Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

+12 -11
+12 -11
kernel/trace/trace_events_filter.c
··· 750 750 * 751 751 * Note: 752 752 * - @str might not be NULL-terminated if it's of type DYN_STRING 753 - * or STATIC_STRING 753 + * or STATIC_STRING, unless @len is zero. 754 754 */ 755 755 756 756 static int regex_match_full(char *str, struct regex *r, int len) 757 757 { 758 - if (strncmp(str, r->pattern, len) == 0) 759 - return 1; 760 - return 0; 758 + /* len of zero means str is dynamic and ends with '\0' */ 759 + if (!len) 760 + return strcmp(str, r->pattern) == 0; 761 + 762 + return strncmp(str, r->pattern, len) == 0; 761 763 } 762 764 763 765 static int regex_match_front(char *str, struct regex *r, int len) 764 766 { 765 - if (len < r->len) 767 + if (len && len < r->len) 766 768 return 0; 767 769 768 - if (strncmp(str, r->pattern, r->len) == 0) 769 - return 1; 770 - return 0; 770 + return strncmp(str, r->pattern, r->len) == 0; 771 771 } 772 772 773 773 static int regex_match_middle(char *str, struct regex *r, int len) 774 774 { 775 - if (strnstr(str, r->pattern, len)) 776 - return 1; 777 - return 0; 775 + if (!len) 776 + return strstr(str, r->pattern) != NULL; 777 + 778 + return strnstr(str, r->pattern, len) != NULL; 778 779 } 779 780 780 781 static int regex_match_end(char *str, struct regex *r, int len)