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

Potential security issue in src/tool_operate.c: Unchecked return from initialization function #5416

Closed
wants to merge 1 commit into from

Conversation

@monocle-ai
Copy link

@monocle-ai monocle-ai commented May 18, 2020

What is a Conditionally Uninitialized Variable? The return value of a function that is potentially used to initialize a local variable is not checked. Therefore, reading the local variable may result in undefined behavior.

6 instances of this defect were found in the following locations:

Instance 1
File : src/tool_operate.c
Function: curl_easy_getinfo

curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &oserrno);

Code extract:

    else if(config->retry_connrefused &&
            (CURLE_COULDNT_CONNECT == result)) {
      long oserrno;
      curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &oserrno); <------ HERE
      if(ECONNREFUSED == oserrno)
        retry = RETRY_CONNREFUSED;

Instance 2
File : src/tool_operate.c
Function: curl_easy_getinfo

curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);

Code extract:

         returned due to such an error, check for HTTP transient
         errors to retry on. */
      long protocol;
      curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol); <------ HERE
      if((protocol == CURLPROTO_HTTP) || (protocol == CURLPROTO_HTTPS)) {
        /* This was HTTP(S) */

Instance 3
File : src/tool_operate.c
Function: curl_easy_getinfo

curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);

Code extract:

      curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
      if((protocol == CURLPROTO_HTTP) || (protocol == CURLPROTO_HTTPS)) {
        /* This was HTTP(S) */
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); <------ HERE

        switch(response) {

Instance 4
File : src/tool_operate.c
Function: curl_easy_getinfo

curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);

Code extract:

    else if(result) {
      long protocol;

      curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); <------ HERE
      curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);

Instance 5
File : src/tool_operate.c
Function: curl_easy_getinfo

curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);

Code extract:

      long protocol;

      curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
      curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol); <------ HERE

      if((protocol == CURLPROTO_FTP || protocol == CURLPROTO_FTPS) &&

Instance 6
File : src/tool_operate.c
Function: curl_easy_getinfo

curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);

Code extract:

      if(effective_url &&
         curl_strnequal(effective_url, "http", 4)) {
        /* This was HTTP(S) */
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); <------ HERE
        if(response != 200 && response != 206) {
          per->metalink_next_res = 1;
Copy link
Member

@bagder bagder left a comment

I think these changes are "okay". They're not strictly necessary since the getinfo function will always assign the long, but we could still do this to be clearer to the reader.

However, I think we should make sure to assign/clear the variable on the same line as the declaration, not insert a new line just below.

@bagder bagder closed this in c4df1f7 May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.