|PATCH] dsdb group audit test : Fix string compares

Gary Lockyer gary at catalyst.net.nz
Sun Nov 18 22:48:08 UTC 2018


With the actual patch attached this time.



On 19/11/18 09:11, Gary Lockyer via samba-technical wrote:
> New patch set with requested changes.
> 
> CI run: https://gitlab.com/samba-team/devel/samba/pipelines/37033885
> 
> Thanks
> 
> Gary
> 
> On 15/11/18 21:24, Andreas Schneider wrote:
>> On Wednesday, 14 November 2018 21:38:25 CET Gary Lockyer via samba-technical 
>> wrote:
>>> Replace the uses of:
>>>     strncmp(expected, value, strlen(expected))
>>> With:
>>>     strcmp(expected, value)
>>
>> I've you're already changing it, please do:
>>
>> int cmp;
>>
>> cmp = strcmp("groupChange", value);
>> if (cmp != 0)
>> ...
>>
>> for both hunks ...
>>
> 
-------------- next part --------------
From 4185781790be2a47f332ec49bf0a0b1c4c158b8d Mon Sep 17 00:00:00 2001
From: Gary Lockyer <gary at catalyst.net.nz>
Date: Wed, 14 Nov 2018 14:03:37 +1300
Subject: [PATCH] dsdb group_audit tests: fix use of strncmp

Replace the uses of:
   strncmp(expected, value, strlen(expected))
With:
    strcmp(expected, value)

Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
---
 .../dsdb/samdb/ldb_modules/tests/test_group_audit.c   | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c b/source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c
index 6ec218beb54..241c0534dae 100644
--- a/source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c
+++ b/source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c
@@ -113,6 +113,8 @@ static void _check_group_change_message(
 	json_t *audit = NULL;
 	json_t *v = NULL;
 	const char* value;
+	int cmp;
+
 	json = messages[message];
 
 	/*
@@ -137,7 +139,8 @@ static void _check_group_change_message(
 	}
 
 	value = json_string_value(v);
-	if (strncmp("groupChange", value, strlen("groupChange") != 0)) {
+	cmp = strcmp("groupChange", value);
+	if (cmp != 0) {
 		cm_print_error(
 		    "Unexpected type \"%s\" != \"groupChange\"\n",
 		    value);
@@ -172,7 +175,8 @@ static void _check_group_change_message(
 	}
 
 	value = json_string_value(v);
-	if (strncmp(user, value, strlen(user) != 0)) {
+	cmp = strcmp(user, value);
+	if (cmp != 0) {
 		cm_print_error(
 		    "Unexpected user name \"%s\" != \"%s\"\n",
 		    value,
@@ -190,7 +194,8 @@ static void _check_group_change_message(
 	}
 
 	value = json_string_value(v);
-	if (strncmp(action, value, strlen(action) != 0)) {
+	cmp = strcmp(action, value);
+	if (cmp != 0) {
 		print_error(
 		    "Unexpected action \"%s\" != \"%s\"\n",
 		    value,
-- 
2.17.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20181119/97e13e38/signature.sig>


More information about the samba-technical mailing list