Staging
v0.5.1
https://github.com/python/cpython
Revision 8497f0a85d97e1d9660bbb450ba9f2dc8b03f87d authored by Giampaolo Rodolà on 07 December 2010, 18:54:43 UTC, committed by Giampaolo Rodolà on 07 December 2010, 18:54:43 UTC
1 parent 1740947
Raw File
Tip revision: 8497f0a85d97e1d9660bbb450ba9f2dc8b03f87d authored by Giampaolo Rodolà on 07 December 2010, 18:54:43 UTC
backporting security fix of issue 9129 (smtpd module vulnerable to DoS attacks in case of connection bashing)
Tip revision: 8497f0a
pystrcmp.c
/* Cross platform case insensitive string compare functions
 */

#include "Python.h"

int
PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size)
{
    if (size == 0)
        return 0;
    while ((--size > 0) &&
           (tolower((unsigned)*s1) == tolower((unsigned)*s2))) {
        if (!*s1++ || !*s2++)
            break;
    }
    return tolower((unsigned)*s1) - tolower((unsigned)*s2);
}

int
PyOS_mystricmp(const char *s1, const char *s2)
{
    while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
        ;
    }
    return (tolower((unsigned)*s1) - tolower((unsigned)*s2));
}
back to top