Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8043720

(smartcardio) Native memory should be handled more accurately

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: security-libs
    • Labels:

      Backports

        Description

        There are a few issues with the native memory allocation in share/native/sun/security/smartcardio/pcsc.c:

        1)
            readerState = calloc(readers, sizeof(SCARD_READERSTATE));
            if (readerState == NULL) {
                throwOutOfMemoryError(env, NULL);

        calloc() can return NULL due to readers be zero.
        In this case OOM would be confusing.

        2)
            for (i = 0; i < readers; i++) {
                free((char *)readerState[i].szReader);
            }

        We can get here upon an error, so readerState[i].szReader may not be initialized.

        3)
            mszReaders = malloc(size);
            if (mszReaders == NULL) {
                throwOutOfMemoryError(env, NULL);
                return NULL;
            }

        If size happens to be zero, we'll get a confusing OOM.

        4)
            tab = (char **)malloc(cnt * sizeof(char *));
            if (tab == NULL) {
                throwOutOfMemoryError(env, NULL);
                return NULL;
            }

        Again, we can get NULL from malloc, if cnt == 0.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                igerasim Ivan Gerasimov
                Reporter:
                igerasim Ivan Gerasimov
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: