Skip to content
Memory corruption Disclosed report Intermediate

Use of Unsafe function || Strcpy

The report claims that the curl project uses the unsafe strcpy function in test helper files, which could cause a buffer overflow if a value longer than the destination buffer is copied. An attacker might exploit this to overwrite memory, though the report does not demonstrate a working exploit.

shobhit2401200 Follow

Originally disclosed on HackerOne

  • Disclosed after 19 days

Summary:

It was observed that application is using strcpy() function which may cause buffer overflow attacks.

#Affected Code https://github.com/curl/curl

Affected Lines

  1. Line 195 of curl-master\tests\libtest\stub_gssapi.c
  2. Line 204,212,216 curl-master\tests\server\socksd.c

Steps To Reproduce:

Lets first discuss what is the issue with strcpy function. basically it takes 2 arguments 1 dst 2 source. the issue is if the dst size is small and the source size is more without a null terminating value so it will overwrite the memory. so in these case 1 got the several lines about strcpy function. but i'm discussing 1 with you rest with remain the same.

    else if(!strcmp(key, "backend")) {
      strcpy(config.addr, value);

    else if(!strcmp(key, "password")) {
      strcpy(config.password, value);

char addr[32]; /* backend IPv4 numerical */ char user[256]; char password[256];

here it is copying the value into config.addr and the size of addr is 32 and same goes for password is 256. now let suppose the value of value is more than 32 in case of add and in case of password it is more than 256. than it can be buffer overflow attack here. so here it will be secure if you use the functions like snprintf , strlcpy. or dynamically assign the size to the array.

Supporting Material/References:

https://cwe.mitre.org/data/definitions/676.html https://www.geeksforgeeks.org/why-strcpy-and-strncpy-are-not-safe-to-use/

Recommendation:

It is recommended to use below mentioned functions to avoid buffer overflow attacks

  1. snprintf
  2. strlcpy
  • [attachment / reference]

Please find the attached screenshots for your reference.

Impact

The strcpy() function does not specify the size of the destination array, so buffer overrun is often a risk. Using strcpy() function to copy a large character array into a smaller one is dangerous, but if the string will fit, then it will not be worth the risk. If the destination string is not large enough to store the source string then the behavior of strcpy() is unspecified or undefined.

Attachments

Screenshot_(640).png
Screenshot_(640).png From the original on HackerOne
Screenshot_(641).png
Screenshot_(641).png

The original report as published on HackerOne, by shobhit2401200. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the code uses strcpy without checking the length of the source string against the destination buffer size.

Impact

If the destination string is not large enough, the behaviour is undefined and could lead to a buffer overflow, though the report does not show a practical exploit.

What the attacker needed

Attacker controls input to the affected fields; input length exceeds buffer size

The fix

The code should be fixed by replacing strcpy with safer functions like snprintf or strlcpy, or by dynamically allocating the correct size.

How it was found

  1. Identify the strcpy calls in the affected files.
  2. Note that config.addr is 32 bytes and config.password is 256 bytes.
  3. If the input value exceeds these sizes, a buffer overflow can occur.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

The program copies text into a fixed-size box without checking if the text fits. If the text is too long, it spills over into nearby memory, which can crash the program. This is called a buffer overflow.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.