Giter VIP home page Giter VIP logo

Comments (4)

GoogleCodeExporter avatar GoogleCodeExporter commented on September 27, 2024
Can you be more specific on how you replaced 'strdup' and 'strcpy' with malloc 
please?

Original comment by [email protected] on 14 May 2012 at 5:10

from py-bcrypt.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 27, 2024
To clear any possible misunderstandings, I replaced "strdup" with "malloc and 
strcpy". I did not replace "'strdup' and 'strcpy' with malloc". Here is the new 
method...


static PyObject *
bcrypt_hashpw(PyObject *self, PyObject *args, PyObject *kw_args)
{
    static char *keywords[] = { "password", "salt", NULL };
    char *password = NULL, *salt = NULL;
    char *ret;

    if (!PyArg_ParseTupleAndKeywords(args, kw_args, "ss:hashpw", keywords,
        &password, &salt))
                return NULL;

    char *password_copy = malloc (strlen (password) + 1);
    if (password_copy == NULL) return NULL;
    strcpy(password_copy, password);

    char *salt_copy = malloc (strlen (salt) + 1);
    if (salt_copy == NULL) return NULL;
    strcpy(salt_copy, salt);

    Py_BEGIN_ALLOW_THREADS;
    ret = pybc_bcrypt(password_copy, salt_copy);
    Py_END_ALLOW_THREADS;

    free(password_copy);
    free(salt_copy);
    if ((ret == NULL) ||
        strcmp(ret, ":") == 0) {
        PyErr_SetString(PyExc_ValueError, "Invalid salt");
        return NULL;
    }

    return PyString_FromString(ret);
}

Original comment by [email protected] on 14 May 2012 at 6:10

from py-bcrypt.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 27, 2024
There is a simpler alternative to re-implementing strdup.

#if defined(_WIN32)
/* On Windows strdup is deprecated, replaced by the ISO C compliant _strdup. */
#define strdup _strdup
#endif

Original comment by [email protected] on 11 Jun 2012 at 1:13

from py-bcrypt.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 27, 2024
I've removed the strdup calls entirely in the current hg tip as part of 
python-3.x support (issue #5). This will be in the forthcoming py-bcrypt-0.4 
and is in the hg tree now.

Original comment by [email protected] on 27 Jul 2013 at 11:58

  • Changed state: Fixed

from py-bcrypt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.