Skip to content

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

Closed
monocle-ai wants to merge 1 commit into
curl:masterfrom
monocle-ai:tool_operate-cuv-2020-05-18-08-59-46-5416
Closed

Potential security issue in src/tool_operate.c: Unchecked return from initialization function#5416
monocle-ai wants to merge 1 commit into
curl:masterfrom
monocle-ai:tool_operate-cuv-2020-05-18-08-59-46-5416

Conversation

@monocle-ai

Copy link
Copy Markdown

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;

@bagder bagder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants