From 65f68639f72afe37ae36b424bd86a67a2fb7ffd1 Mon Sep 17 00:00:00 2001 From: apocelipes Date: Wed, 23 Oct 2024 17:14:22 +0800 Subject: [PATCH] Editor: optimize editor version parsing --- src/detection/editor/editor.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/detection/editor/editor.c b/src/detection/editor/editor.c index 8a0e58cd6..8617b8a26 100644 --- a/src/detection/editor/editor.c +++ b/src/detection/editor/editor.c @@ -134,24 +134,14 @@ const char* ffDetectEditor(FFEditorResult* result) return NULL; ffStrbufSubstrBeforeFirstC(&result->version, '\n'); - for (uint32_t iStart = 0; iStart < result->version.length; ++iStart) - { - char c = result->version.chars[iStart]; - if (ffCharIsDigit(c)) - { - for (uint32_t iEnd = iStart + 1; iEnd < result->version.length; ++iEnd) - { - char c = result->version.chars[iEnd]; - if (isspace(c)) - { - ffStrbufSubstrBefore(&result->version, iEnd); - break; - } - } - if (iStart > 0) - ffStrbufSubstrAfter(&result->version, iStart - 1); - break; - } + const char* versionStart = strpbrk(result->version.chars, "0123456789"); + if (versionStart != NULL) { + const char* versionEnd = strpbrk(versionStart, " \t\v\f"); + if (versionEnd != NULL) + ffStrbufSubstrBefore(&result->version, (uint32_t)(versionEnd - result->version.chars)); + + if (versionStart != result->version.chars) + ffStrbufSubstrAfter(&result->version, (uint32_t)(versionStart - result->version.chars - 1)); } return NULL;