CVE-2022-0351 - Access of Memory Location Before Start of Buffer

Severity

78%

Complexity

18%

Confidentiality

98%

Access of Memory Location Before Start of Buffer in Conda vim prior to 8.2.

Access of Memory Location Before Start of Buffer in GitHub repository vim/vim prior to 8.2.

CVSS 3.1 Base Score 7.8. CVSS Attack Vector: local. CVSS Attack Complexity: low. CVSS Vector: (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

CVSS 2.0 Base Score 4.6. CVSS Attack Vector: local. CVSS Attack Complexity: low. CVSS Vector: (AV:L/AC:L/Au:N/C:P/I:P/A:P).

Demo Examples

Access of Memory Location Before Start of Buffer

CWE-786

In the following C/C++ example, a utility function is used to trim trailing whitespace from a character string. The function copies the input string to a local character string and uses a while statement to remove the trailing whitespace by moving backward through the string and overwriting whitespace with a NUL character.


               
}
return retMessage;// copy input string to a temporary string
message[index] = strMessage[index];
// trim trailing whitespace
len--;
// return string without trailing whitespace

However, this function can cause a buffer underwrite if the input character string contains all whitespace. On some systems the while statement will move backwards past the beginning of a character string and will call the isspace() function on an address outside of the bounds of the local buffer.

Access of Memory Location Before Start of Buffer

CWE-786

The following example asks a user for an offset into an array to select an item.


               
}
printf("You selected %s\n", items[index-1]);

The programmer allows the user to specify which element in the list to select, however an attacker can provide an out-of-bounds offset, resulting in a buffer over-read (CWE-126).

Access of Memory Location Before Start of Buffer

CWE-786

The following is an example of code that may result in a buffer underwrite, if find() returns a negative value to indicate that ch is not found in srcBuf:


               
}
...

If the index to srcBuf is somehow under user control, this is an arbitrary write-what-where condition.

Demo Examples

Improper Restriction of Operations within the Bounds of a Memory Buffer

CWE-119

This example takes an IP address from a user, verifies that it is well formed and then looks up the hostname and copies it into a buffer.


               
}
strcpy(hostname, hp->h_name);/*routine that ensures user_supplied_addr is in the right format for conversion */

This function allocates a buffer of 64 bytes to store the hostname, however there is no guarantee that the hostname will not be larger than 64 bytes. If an attacker specifies an address which resolves to a very large hostname, then we may overwrite sensitive data or even relinquish control flow to the attacker.

Note that this example also contains an unchecked return value (CWE-252) that can lead to a NULL pointer dereference (CWE-476).

Improper Restriction of Operations within the Bounds of a Memory Buffer

CWE-119

This example applies an encoding procedure to an input string and stores it into a buffer.


               
}
return dst_buf;
die("user string too long, die evil hacker!");
else dst_buf[dst_index++] = user_supplied_string[i];
dst_buf[dst_index++] = ';';
/* encode to < */

The programmer attempts to encode the ampersand character in the user-controlled string, however the length of the string is validated before the encoding procedure is applied. Furthermore, the programmer assumes encoding expansion will only expand a given character by a factor of 4, while the encoding of the ampersand expands by 5. As a result, when the encoding procedure expands the string it is possible to overflow the destination buffer if the attacker provides a string of many ampersands.

Improper Restriction of Operations within the Bounds of a Memory Buffer

CWE-119

The following example asks a user for an offset into an array to select an item.


               
}
printf("You selected %s\n", items[index-1]);

The programmer allows the user to specify which element in the list to select, however an attacker can provide an out-of-bounds offset, resulting in a buffer over-read (CWE-126).

Improper Restriction of Operations within the Bounds of a Memory Buffer

CWE-119

In the following code, the method retrieves a value from an array at a specific array index location that is given as an input parameter to the method


               
}
return value;// check that the array index is less than the maximum// length of the array
value = array[index];// get the value at the specified index of the array
// if array index is invalid then output error message// and return value indicating error
value = -1;

However, this method only verifies that the given array index is less than the maximum length of the array but does not check for the minimum value (CWE-839). This will allow a negative value to be accepted as the input array index, which will result in a out of bounds read (CWE-125) and may allow access to sensitive memory. The input array index should be checked to verify that is within the maximum and minimum range required for the array (CWE-129). In this example the if statement should be modified to include a minimum range check, as shown below.


               
...// check that the array index is within the correct// range of values for the array

Improper Restriction of Operations within the Bounds of a Memory Buffer

CWE-119

Windows provides the _mbs family of functions to perform various operations on multibyte strings. When these functions are passed a malformed multibyte string, such as a string containing a valid leading byte followed by a single null byte, they can read or write past the end of the string buffer causing a buffer overflow. The following functions all pose a risk of buffer overflow: _mbsinc _mbsdec _mbsncat _mbsncpy _mbsnextc _mbsnset _mbsrev _mbsset _mbsstr _mbstok _mbccpy _mbslen

Overview

First reported 3 years ago

2022-01-25 18:15:00

Last updated 2 years ago

2022-11-09 19:20:00

Affected Software

Debian Linux 9.0

9.0

References

https://github.com/vim/vim/commit/fe6fb267e6ee5c5da2f41889e4e0e0ac5bf4b89d

https://huntr.dev/bounties/8b36db58-b65c-4298-be7f-40b9e37fd161

https://github.com/vim/vim/commit/fe6fb267e6ee5c5da2f41889e4e0e0ac5bf4b89d

Patch, Third Party Advisory

https://huntr.dev/bounties/8b36db58-b65c-4298-be7f-40b9e37fd161

Exploit, Third Party Advisory

[debian-lts-announce] 20220516 [SECURITY] [DLA 3011-1] vim security update

[debian-lts-announce] 20220516 [SECURITY] [DLA 3011-1] vim security update

Mailing List, Third Party Advisory

GLSA-202208-32

GLSA-202208-32

Third Party Advisory

https://support.apple.com/kb/HT213488

https://support.apple.com/kb/HT213444

20221030 APPLE-SA-2022-10-27-5 Additional information for APPLE-SA-2022-10-24-2 macOS Ventura 13

20221030 APPLE-SA-2022-10-24-2 macOS Ventura 13

20221030 APPLE-SA-2022-10-27-7 Additional information for APPLE-SA-2022-09-12-4 macOS Monterey 12.6

https://support.apple.com/kb/HT213488

Vendor Advisory

https://support.apple.com/kb/HT213444

Vendor Advisory

20221030 APPLE-SA-2022-10-27-5 Additional information for APPLE-SA-2022-10-24-2 macOS Ventura 13

Third Party Advisory

20221030 APPLE-SA-2022-10-24-2 macOS Ventura 13

Third Party Advisory

20221030 APPLE-SA-2022-10-27-7 Additional information for APPLE-SA-2022-09-12-4 macOS Monterey 12.6

Third Party Advisory

[debian-lts-announce] 20221108 [SECURITY] [DLA 3182-1] vim security update

20221030 APPLE-SA-2022-10-27-5 Additional information for APPLE-SA-2022-10-24-2 macOS Ventura 13

Mailing List, Third Party Advisory

20221030 APPLE-SA-2022-10-24-2 macOS Ventura 13

Mailing List, Third Party Advisory

20221030 APPLE-SA-2022-10-27-7 Additional information for APPLE-SA-2022-09-12-4 macOS Monterey 12.6

Mailing List, Third Party Advisory

[debian-lts-announce] 20221108 [SECURITY] [DLA 3182-1] vim security update

Mailing List, Third Party Advisory

Stay updated

ExploitPedia is constantly evolving. Sign up to receive a notification when we release additional functionality.

Get in touch

If you'd like to report a bug or have any suggestions for improvements then please do get in touch with us using this form. We will get back to you as soon as we can.