lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 29 Nov 2010 06:11:21 +0300
From:	Pavel Vasilyev <pavel@...linux.ru>
To:	Ming Lei <tom.leiming@...il.com>
CC:	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] Repalce strncmp by memcmp

On 29.11.2010 05:29, Ming Lei wrote:
> Hi,
>
> 2010/11/29 Pavel Vasilyev <pavel@...linux.ru>:
>>    This patch replace all strncmp(a, b, c) by  memcmp(a, b, c).
>>
>> I test on x86_64 (AMD Opteron 285).
> In fact, memcmp doesn't handle case of tail of string, so
> it is not safe to replace strncmp with memcmp
>
#include <stdio.h>
#include <errno.h>

int main() {

   char *STR = "XXXX\0";
   char *XXX = "XXXX";
   int a, b;

     errno = 0; a = memcmp(STR, XXX, 5);  a += errno;
     errno = 0; b = strncmp(STR, XXX, 5); b += errno;
     printf("5 chars: %d %d \n", a, b);
     errno = 0; a = memcmp(STR, XXX, 4);  a += errno;
     errno = 0; b = strncmp(STR, XXX, 4); b += errno;
     printf("4 chars: %d %d \n", a, b);

     printf("SWAP STRINGS\n");

     errno = 0; a = memcmp(XXX, STR, 5);  a += errno;
     errno = 0; b = strncmp(XXX, STR, 5); b += errno;
     printf("5 chars: %d %d \n", a, b);
     errno = 0; a = memcmp(XXX, STR, 4);  a += errno;
     errno = 0; b = strncmp(XXX, STR, 4); b += errno;
     printf("4 chars: %d %d \n", a, b);

return 0;
}
----
# ./a.out
5 chars: 0 0
4 chars: 0 0
SWAP STRINGS
5 chars: 0 0
4 chars: 0 0

But I think the same thing  ;)

-- 

                                                         Pavel.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ