static void DetectTransformCompressWhitespaceRegisterTests(void);
#endif
static void TransformCompressWhitespace(InspectionBuffer *buffer, void *options);
+static bool TransformCompressWhitespaceValidate(
+ const uint8_t *content, uint16_t content_len, void *options);
void DetectTransformCompressWhitespaceRegister(void)
{
"/rules/transforms.html#compress-whitespace";
sigmatch_table[DETECT_TRANSFORM_COMPRESS_WHITESPACE].Transform =
TransformCompressWhitespace;
+ sigmatch_table[DETECT_TRANSFORM_COMPRESS_WHITESPACE].TransformValidate =
+ TransformCompressWhitespaceValidate;
sigmatch_table[DETECT_TRANSFORM_COMPRESS_WHITESPACE].Setup =
DetectTransformCompressWhitespaceSetup;
#ifdef UNITTESTS
SCReturnInt(r);
}
+/*
+ * \brief Validate content bytes to see if it's compatible with this transform
+ * \param content Byte array to check for compatibility
+ * \param content_len Number of bytes to check
+ * \param options Ignored
+ * \retval false If the string contains spaces
+ * \retval true Otherwise.
+ */
+static bool TransformCompressWhitespaceValidate(
+ const uint8_t *content, uint16_t content_len, void *options)
+{
+ if (content) {
+ for (uint32_t i = 0; i < content_len; i++) {
+ if (!isspace(*content++)) {
+ continue;
+ }
+ if ((i + 1) < content_len && isspace(*content)) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
static void TransformCompressWhitespace(InspectionBuffer *buffer, void *options)
{
const uint8_t *input = buffer->inspect;
uint32_t input_len = strlen((char *)input);
InspectionBuffer buffer;
- InspectionBufferInit(&buffer, 8);
+ InspectionBufferInit(&buffer, 9);
InspectionBufferSetup(&buffer, input, input_len);
PrintRawDataFp(stdout, buffer.inspect, buffer.inspect_len);
TransformCompressWhitespace(&buffer, NULL);
uint32_t input_len = strlen((char *)input);
InspectionBuffer buffer;
- InspectionBufferInit(&buffer, 8);
+ InspectionBufferInit(&buffer, 9);
InspectionBufferSetup(&buffer, input, input_len);
PrintRawDataFp(stdout, buffer.inspect, buffer.inspect_len);
TransformDoubleWhitespace(&buffer);
PASS;
}
+static int DetectTransformCompressWhitespaceTest03(void)
+{
+ const uint8_t *input = (const uint8_t *)" A B C D ";
+ uint32_t input_len = strlen((char *)input);
+
+ InspectionBuffer buffer;
+ InspectionBufferInit(&buffer, 10);
+ InspectionBufferSetup(&buffer, input, input_len);
+ PrintRawDataFp(stdout, buffer.inspect, buffer.inspect_len);
+ FAIL_IF(TransformCompressWhitespaceValidate(buffer.inspect, buffer.inspect_len, NULL));
+ PASS;
+}
+
+static int DetectTransformCompressWhitespaceTest04(void)
+{
+ const uint8_t *input = (const uint8_t *)" A B C D ";
+ uint32_t input_len = strlen((char *)input);
+
+ InspectionBuffer buffer;
+ InspectionBufferInit(&buffer, 9);
+ InspectionBufferSetup(&buffer, input, input_len);
+ TransformDoubleWhitespace(&buffer);
+ PrintRawDataFp(stdout, buffer.inspect, buffer.inspect_len);
+ FAIL_IF(TransformCompressWhitespaceValidate(buffer.inspect, buffer.inspect_len, NULL));
+ PASS;
+}
+
static void DetectTransformCompressWhitespaceRegisterTests(void)
{
UtRegisterTest("DetectTransformCompressWhitespaceTest01",
DetectTransformCompressWhitespaceTest01);
UtRegisterTest("DetectTransformCompressWhitespaceTest02",
DetectTransformCompressWhitespaceTest02);
+ UtRegisterTest(
+ "DetectTransformCompressWhitespaceTest03", DetectTransformCompressWhitespaceTest03);
+ UtRegisterTest(
+ "DetectTransformCompressWhitespaceTest04", DetectTransformCompressWhitespaceTest04);
}
-#endif
\ No newline at end of file
+#endif