Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace "new" variable #1782

Closed
hirotakaster opened this issue Jun 25, 2018 · 12 comments
Closed

Replace "new" variable #1782

hirotakaster opened this issue Jun 25, 2018 · 12 comments
Assignees
Labels
bug help-wanted This issue is not being actively worked on, but PRs welcome.

Comments

@hirotakaster
Copy link

Description

  • Type: Enhancement
  • Priority: Minor

Enhancement

I would like to replace variable "*new" to "*new_cert" in ssl_append_key_cert function at ssl_tls.c like a following, because of my build with arm-none-eabi-gcc(c++) will fail on this "new" variable.

now

static int ssl_append_key_cert( mbedtls_ssl_key_cert **head,
                                mbedtls_x509_crt *cert,
                                mbedtls_pk_context *key )
{
    mbedtls_ssl_key_cert *new;

    new = mbedtls_calloc( 1, sizeof( mbedtls_ssl_key_cert ) );
    if( new == NULL )
        return( MBEDTLS_ERR_SSL_ALLOC_FAILED );

    new->cert = cert;
    new->key  = key;
    new->next = NULL;

    /* Update head is the list was null, else add to the end */
    if( *head == NULL )
    {
        *head = new;
    }
    else
    {
        mbedtls_ssl_key_cert *cur = *head;
        while( cur->next != NULL )
            cur = cur->next;
        cur->next = new;
    }

    return( 0 );
}

to

static int ssl_append_key_cert( mbedtls_ssl_key_cert **head,
                                mbedtls_x509_crt *cert,
                                mbedtls_pk_context *key )
{
    mbedtls_ssl_key_cert *new_cert;

    new_cert = mbedtls_calloc( 1, sizeof( mbedtls_ssl_key_cert ) );
    if( new_key_cert == NULL )
        return( MBEDTLS_ERR_SSL_ALLOC_FAILED );

    new_cert->cert = cert;
    new_cert->key  = key;
    new_cert->next = NULL;

    /* Update head is the list was null, else add to the end */
    if( *head == NULL )
    {
        *head = new_cert;
    }
    else
    {
        mbedtls_ssl_key_cert *cur = *head;
        while( cur->next != NULL )
            cur = cur->next;
        cur->next = new_cert;
    }

    return( 0 );
}
@hanno-becker
Copy link

Hi @hirotakaster, thank you for your report!

I don't see a reason not to perform the suggested renaming if the current naming causes problems on some build systems. Do you have time to open a PR with the change?

Thank you,
Hanno, Mbed TLS team member

@hirotakaster
Copy link
Author

Hi @hanno-arm ,

Okay, I would send a PR with this change.

Thank you,
Hirotaka Niisato

@hanno-becker
Copy link

Hi @hirotakaster,

great, thank you!

Best,
Hanno

@hanno-becker hanno-becker added the help-wanted This issue is not being actively worked on, but PRs welcome. label Jun 25, 2018
@hanno-becker hanno-becker self-assigned this Jun 25, 2018
@RonEld
Copy link
Contributor

RonEld commented Jun 25, 2018

@hirotakaster Since this causes your build to fail, I would consider this a bug, rather than an enhancement.

@ciarmcom
Copy link

ARM Internal Ref: IOTSSL-2374

@gilles-peskine-arm
Copy link
Contributor

@hirotakaster Could you please let us know what compiler options you're using? Note that Mbed TLS is a C library. It must be compiled with a C compiler. If you use a combined C/C++ compiler, make sure that you're using it in the correct mode. This should be automatic for a file name with the extension .c.

There are more differences between C and C++ than the addition of new as a reserved identifier, for example the size of some integral expressions. Compiling Mbed TLS source files with a C++ compiler is not supported and may lead to subtle bugs. It is fine to use Mbed TLS headers in C++ programs and to link the library in C++ programs, but the library itself must be compiled with a C compiler.

@hirotakaster
Copy link
Author

@gilles-peskine-arm
yes, I build with my C++ source code with build option is included arm-none-eabi-gcc -std=gnu++11.
so if this proposal not suitable and supported in mbedTLS, please revoke this issue and pull request.
Thank you.

@irwir
Copy link
Contributor

irwir commented Jun 26, 2018

@gilles-peskine-arm

It must be compiled with a C compiler.

According to an old issue #447

Compiling under C++ should be tested, and whatever issues are found, should be fixed.

In that case, none of C++ reserved words could be used as identifiers.

@gilles-peskine-arm
Copy link
Contributor

@irwir Thanks for mentioning this old issue! But I'm with Guido Vranken on this one: shoehorning C code into being compilable C++ is risky, and it is not needed to link C code into an application that is otherwise written in C++.

@hirotakaster
Copy link
Author

@gilles-peskine-arm Thank you, then I should revoke & close this issue&PR? I understood your points and risk, and I see mbedTLS support/maintain under C language written in tutorial.

@irwir
Copy link
Contributor

irwir commented Jun 26, 2018

@gilles-peskine-arm

But I'm with Guido Vranken on this one

Interesting example, though.
That was C99 standard allowing variable sized local arrays, while all C++ implementations were non-standard extensions.

Giving more meaningful name to variables is a positive change, not a risky one.

simonbutcher pushed a commit to simonbutcher/mbedtls that referenced this issue Jun 29, 2018
simonbutcher pushed a commit to simonbutcher/mbedtls that referenced this issue Jun 29, 2018
@simonbutcher
Copy link
Contributor

All PR's, #1783 for development, #1819 for mbedtls-2.7, and #1820 for mbedtls-2.1 have been merged, fixing the issue, so this can now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted This issue is not being actively worked on, but PRs welcome.
Projects
None yet
Development

No branches or pull requests

7 participants