Skip to content
Memory corruption Disclosed report Advanced

Telnet Suboption Buffer Pointer Underflow in lib/telnet.c leads to Out-of-Bounds Read

In curl's telnet handler, the suboption buffer pointer is decremented unconditionally even when the buffer is full and nothing was written, so the pointer moves before the start of the buffer. A malicious telnet server could then cause an out-of-bounds read, leaking adjacent memory in verbose mode or possibly crashing curl.

stif Follow

Originally disclosed on HackerOne

  • Disclosed after 24 hours

Summary

A buffer pointer underflow vulnerability exists in curl's telnet protocol handler (lib/telnet.c). When processing telnet suboptions in the CURL_TS_SE state, the code unconditionally decrements the suboption buffer pointer by 2 (subpointer -= 2), even when the CURL_SB_ACCUM macro skips writing due to a full buffer. This leads to an out-of-bounds read when suboption() and printsub() are subsequently called.

Affected Version

  • All curl versions with telnet support containing this code pattern
  • Tested on latest curl source from GitHub (master branch)
  • File: lib/telnet.c
  • Vulnerable lines: 1210 and 1226

Technical Analysis

Vulnerable Code Pattern

In lib/telnet.c, the CURL_SB_ACCUM macro (lines 69-73) conditionally writes to the buffer:

C
#define CURL_SB_ACCUM(x, c)                                   \
  do {                                                        \
    if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \
      *x->subpointer++ = (c);                                 \
  } while(0)

However, in the CURL_TS_SE state handling (lines 1207-1211 and 1223-1227), the pointer decrement is unconditional:

Path 1 (line 1207-1211):

C
CURL_SB_ACCUM(tn, CURL_IAC);
CURL_SB_ACCUM(tn, c);
tn->subpointer -= 2;    // UNCONDITIONAL - causes underflow when buffer is full
CURL_SB_TERM(tn);

Path 2 (line 1223-1227):

C
CURL_SB_ACCUM(tn, CURL_IAC);
CURL_SB_ACCUM(tn, CURL_SE);
tn->subpointer -= 2;    // UNCONDITIONAL - causes underflow when buffer is full
CURL_SB_TERM(tn);

Exploitation Flow

  1. Malicious telnet server sends suboption data to fill the 512-byte buffer (SUBBUFSIZE)
  2. Server sends IAC followed by another byte while buffer is full
  3. CURL_SB_ACCUM macro does nothing (buffer full check passes)
  4. subpointer -= 2 executes unconditionally, causing pointer underflow
  5. CURL_SB_TERM sets subend = subpointer (now pointing before buffer start)
  6. suboption() is called with corrupted pointer
  7. CURL_SB_LEN macro calculates negative/wrapped length
  8. printsub() reads out-of-bounds memory in verbose mode

Memory Layout (struct TELNET)

C
struct TELNET {
  // ... other fields ...
  struct dynbuf out;              // Contains heap pointers
  unsigned char subbuffer[512];   // The suboption buffer
  unsigned char *subpointer;      // Points into subbuffer
  unsigned char *subend;          // End marker
  // ...
};

When subpointer underflows, it points to the dynbuf out structure, which contains heap pointers that may be leaked.

Steps To Reproduce

  1. Save the attached PoC script as curl_telnet_poc.py

  2. Run the malicious telnet server:

Bash
python3 curl_telnet_poc.py -p 2323
  1. In another terminal, connect with curl in verbose mode:
Bash
curl -v telnet://127.0.0.1:2323
  1. Observe the verbose output for:

    • Anomalous suboption data in the output
    • Potential non-printable characters indicating memory leak
    • Possible crash (depending on memory layout)
  2. For better observation, build curl with AddressSanitizer:

Bash
./configure CFLAGS="-fsanitize=address -g"
make
./src/curl -v telnet://127.0.0.1:2323

ASan should report an out-of-bounds read.

Supporting Material/References


## Impact

## Impact

### Security Impact

1. **Information Disclosure (Low-Medium)**: When curl is run in verbose mode (`-v`), the `printsub()` function may read and display memory contents from before the suboption buffer. This could potentially leak:
   - Heap pointers (useful for ASLR bypass in chained exploits)
   - Contents of the `dynbuf out` structure
   - Other sensitive data in adjacent memory

2. **Denial of Service (Low)**: Depending on memory layout and access patterns, the out-of-bounds read could cause a crash.

### Attack Scenario

An attacker controlling a malicious telnet server could:
1. Wait for a victim to connect using `curl -v telnet://malicious-server`
2. Send crafted telnet suboption data to trigger the vulnerability
3. Potentially observe leaked memory contents in error messages or logs
4. Use leaked heap pointers to aid in exploiting other vulnerabilities

### Limitations

- Requires victim to connect to attacker-controlled telnet server
- Most impactful in verbose mode (`-v` flag)
- Telnet protocol is deprecated and rarely used
- No direct code execution capability

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

curl ships a telnet protocol handler in lib/telnet.c. Part of that handler deals with telnet suboption negotiation: the server can send an IAC SB (subnegotiation) sequence carrying option data, terminated by IAC SE. curl accumulates the suboption bytes into a fixed buffer inside its struct TELNET and, when the subnegotiation ends, hands the accumulated data to suboption() for processing. In verbose mode (-v) the same data is also passed to printsub(), which prints it to the user.

The report describes a buffer pointer underflow in that accumulation logic: when the suboption buffer is full, the code still decrements the suboption pointer, so the pointer ends up before the start of the buffer and later reads go out of bounds.

Setup

  • Target: curl, source at https://github.com/curl/curl, file lib/telnet.c.
  • Affected versions: all curl versions with telnet support that contain this code pattern. The researcher tested the latest source from GitHub (master branch).
  • Vulnerable lines: 1210 and 1226.
  • Related macros: lines 63 to 76 (CURL_SB_CLEAR, CURL_SB_TERM, CURL_SB_ACCUM, CURL_SB_GET, CURL_SB_LEN).
  • Preconditions: the victim must connect to an attacker-controlled telnet server, and the impact is greatest when curl runs in verbose mode (-v).
  • Tools used: a Python PoC server script (curl_telnet_poc.py, attached to the report) and, optionally, a curl build with AddressSanitizer.

Finding it

The CURL_SB_ACCUM macro (lines 69 to 73) only writes when there is room left in the buffer:

C
#define CURL_SB_ACCUM(x, c)                                   \
  do {                                                        \
    if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \
      *x->subpointer++ = (c);                                 \
  } while(0)

In the CURL_TS_SE state handling, however, the pointer is moved back by two bytes unconditionally, after two CURL_SB_ACCUM calls that may both have been skipped because the buffer was full. There are two such paths.

Path 1 (lines 1207 to 1211):

C
CURL_SB_ACCUM(tn, CURL_IAC);
CURL_SB_ACCUM(tn, c);
tn->subpointer -= 2;    // UNCONDITIONAL - causes underflow when buffer is full
CURL_SB_TERM(tn);

Path 2 (lines 1223 to 1227):

C
CURL_SB_ACCUM(tn, CURL_IAC);
CURL_SB_ACCUM(tn, CURL_SE);
tn->subpointer -= 2;    // UNCONDITIONAL - causes underflow when buffer is full
CURL_SB_TERM(tn);

The asymmetry is the bug: the write is guarded by a bounds check, the pointer arithmetic that is meant to undo that write is not. When the buffer is full, nothing was written, but the pointer still moves backwards.

Exploitation

The exploitation flow, as described in the report:

  1. A malicious telnet server sends suboption data to fill the 512-byte buffer (SUBBUFSIZE).
  2. The server sends IAC followed by another byte while the buffer is full.
  3. The CURL_SB_ACCUM macro does nothing, because the buffer-full check fails.
  4. subpointer -= 2 executes unconditionally, causing the pointer to underflow.
  5. CURL_SB_TERM sets subend = subpointer, which now points before the start of the buffer.
  6. suboption() is called with the corrupted pointer.
  7. The CURL_SB_LEN macro calculates a negative or wrapped length.
  8. printsub() reads out-of-bounds memory in verbose mode.

Step 1: save the PoC server

Save the attached PoC script as curl_telnet_poc.py.

Step 2: run the malicious telnet server

Bash
python3 curl_telnet_poc.py -p 2323

Run the PoC server with the command from the report.

Step 3: connect with curl in verbose mode

In another terminal:

Bash
curl -v telnet://[redacted]:2323

The -v flag matters: it is what causes printsub() to run and display the suboption data.

Step 4: observe the output

Look in the verbose output for:

  • anomalous suboption data in the output;
  • potential non-printable characters indicating a memory leak;
  • a possible crash, depending on memory layout.

Step 5: confirm with AddressSanitizer

For better observation, build curl with ASan:

Bash
./configure CFLAGS="-fsanitize=address -g"
make
./src/curl -v telnet://[redacted]:2323

ASan should report an out-of-bounds read.

Root cause

The CURL_SB_ACCUM macro is safe on its own: it checks x->subpointer < (x->subbuffer + sizeof(x->subbuffer)) before writing and advancing. The CURL_TS_SE handlers assume that the two preceding CURL_SB_ACCUM calls always advanced the pointer by two, and undo them with tn->subpointer -= 2. When the buffer is full, both accumulations are skipped, so the decrement moves the pointer two bytes before the start of subbuffer. CURL_SB_TERM then records that out-of-bounds position as subend, and the subsequent suboption() and printsub() calls work with a length derived from the corrupted pointers.

The memory layout of struct TELNET explains what sits in front of the buffer:

C
struct TELNET {
  // ... other fields ...
  struct dynbuf out;              // Contains heap pointers
  unsigned char subbuffer[512];   // The suboption buffer
  unsigned char *subpointer;      // Points into subbuffer
  unsigned char *subend;          // End marker
  // ...
};

When subpointer underflows, it points into the dynbuf out structure that precedes subbuffer, which contains heap pointers that may be leaked.

Impact

The report rates the issue as low severity and lists two effects.

  1. Information disclosure (low to medium). In verbose mode, printsub() may read and display memory from before the suboption buffer. This could potentially leak heap pointers (useful for an ASLR bypass in chained exploits), the contents of the dynbuf out structure, and other sensitive data in adjacent memory.
  2. Denial of service (low). Depending on memory layout and access patterns, the out-of-bounds read could cause a crash.

The attack scenario: an attacker controlling a malicious telnet server waits for a victim to connect with curl -v telnet://malicious-server, sends crafted suboption data to trigger the vulnerability, and may then observe leaked memory contents in error messages or logs, using leaked heap pointers to aid in exploiting other vulnerabilities.

The report is explicit about the limits: the victim must connect to an attacker-controlled telnet server, the issue is most impactful in verbose mode (-v), the telnet protocol is deprecated and rarely used, and there is no direct code execution capability.

Fix

The report does not describe a fix or a patch.

Variants to test

  • Other fixed-size accumulation buffers with a matching rollback. Look for macros or helpers that guard a write with a bounds check but pair it with unconditional pointer arithmetic elsewhere. A positive result is a path where the pointer can be moved before the buffer start while the write was skipped.
  • Other telnet state transitions. The report covers the CURL_TS_SE state. Exercise the other states that use CURL_SB_ACCUM, CURL_SB_TERM, CURL_SB_GET and CURL_SB_LEN with a full buffer and watch for lengths that wrap or go negative.
  • Verbose and non-verbose runs. Run the same PoC with and without -v under ASan. A positive result is an out-of-bounds read report in one mode and not the other, which tells you which code path consumes the corrupted pointers.
  • Buffer boundary sizes. Fill the buffer to exactly SUBBUFSIZE and then send the terminating sequence, rather than overfilling it, to see whether the off-by-two rollback alone is enough to underflow.
  • Other curl protocol handlers with fixed buffers. Apply the same reasoning to any handler that keeps a pointer into a fixed array and adjusts it after conditional writes; a positive result is any read whose start address precedes the array.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

curl is a very common command-line program for downloading and sending data over the internet. Besides the usual web protocols, it can also speak telnet, an old protocol for connecting to remote machines with a text terminal. The part of curl that speaks telnet lives in a source file called lib/telnet.c.

Telnet has a feature where the server and the client exchange small control messages called suboptions. curl collects the bytes of a suboption into a fixed-size box in memory (512 bytes) and, when the suboption ends, passes what it collected to another part of the program for handling. If you run curl in verbose mode (-v), which means "show me everything that is going on", the same bytes are also printed to your screen.

The report describes a bug in that collecting logic. When the box is already full, curl is supposed to stop writing into it. It does stop writing, but it still moves its internal bookmark (a pointer) backwards by two positions, as if it had written two bytes. The bookmark then ends up before the start of the box, and later code reads from that wrong place. Reading memory outside the box is called an out-of-bounds read.

A few everyday comparisons help here:

  • Think of the 512-byte buffer as a row of numbered pigeonholes. A pointer is a finger pointing at one pigeonhole. "Writing" means putting a letter in the hole the finger points at, then moving the finger one hole to the right.
  • The bug is like a clerk who is told "if there is room, put two letters in the next two holes and move your finger two holes right". When there is no room, the clerk puts nothing in, but still moves the finger two holes to the left. The finger now points at the wall before the first hole.
  • An out-of-bounds read is then the clerk reading whatever is written on that wall and showing it to the customer.

Context

curl ships a telnet protocol handler in lib/telnet.c. Part of that handler deals with telnet suboption negotiation: the server can send an IAC SB (subnegotiation) sequence carrying option data, terminated by IAC SE. curl accumulates the suboption bytes into a fixed buffer inside its struct TELNET and, when the subnegotiation ends, hands the accumulated data to suboption() for processing. In verbose mode (-v) the same data is also passed to printsub(), which prints it to the user.

The report describes a buffer pointer underflow in that accumulation logic: when the suboption buffer is full, the code still decrements the suboption pointer, so the pointer ends up before the start of the buffer and later reads go out of bounds.

Some terms from that paragraph, from zero:

  • Protocol: an agreed set of rules for how two computers talk. Telnet is one such set of rules, designed in the days of text terminals.
  • Handler: the part of a program that deals with one particular protocol or feature. curl has one handler per protocol.
  • Suboption negotiation: telnet lets the two sides agree on extra features (terminal size, terminal type and so on) by exchanging small control messages. These are the suboptions.
  • IAC SB and IAC SE: telnet control sequences. IAC is a special marker byte meaning "the next byte is a command, not text". SB means "subnegotiation begins" and SE means "subnegotiation ends". So a suboption is everything between IAC SB and IAC SE.
  • Buffer: a reserved area of memory used to hold data temporarily, like a tray where you put incoming letters before sorting them.
  • Pointer: a value that records a memory address, that is, where in memory something sits. Moving a pointer is like moving your finger along a shelf.
  • Underflow: moving a pointer below the lowest valid position, so it points before the start of the area it is supposed to stay in. It is the mirror image of an overflow, where you go past the end.
  • Out-of-bounds read: reading memory outside the area the program intended to read. The program does not crash immediately; it just picks up whatever bytes happen to be there.
  • Verbose mode (-v): a command-line switch that makes a program print detailed diagnostic information about what it is doing.

Setup

  • Target: curl, source at https://github.com/curl/curl, file lib/telnet.c.
  • Affected versions: all curl versions with telnet support that contain this code pattern. The researcher tested the latest source from GitHub (master branch).
  • Vulnerable lines: 1210 and 1226.
  • Related macros: lines 63 to 76 (CURL_SB_CLEAR, CURL_SB_TERM, CURL_SB_ACCUM, CURL_SB_GET, CURL_SB_LEN).
  • Preconditions: the victim must connect to an attacker-controlled telnet server, and the impact is greatest when curl runs in verbose mode (-v).
  • Tools used: a Python PoC server script (curl_telnet_poc.py, attached to the report) and, optionally, a curl build with AddressSanitizer.

What those setup items mean if you are new to this:

  • Source code: the human-readable text that a program is built from. GitHub is a website that hosts such code, and master is the name of the main development line.
  • Line numbers: source files are numbered line by line, so "line 1210" is a precise address inside the file.
  • Macro: a short piece of code that the compiler expands wherever its name appears. It is a way to write a small reusable snippet without the overhead of a function call. The names starting with CURL_SB_ are such snippets for handling the suboption buffer.
  • PoC (proof of concept): a small program written to demonstrate that a bug is real, without doing anything harmful beyond the demonstration.
  • AddressSanitizer (ASan): a tool built into compilers that watches a program while it runs and shouts when the program reads or writes memory it should not touch. It is like a safety inspector standing next to the clerk.
  • Precondition: something that must be true before the bug can be triggered. Here, the victim has to connect to a server the attacker controls.

Finding it

The CURL_SB_ACCUM macro (lines 69 to 73) only writes when there is room left in the buffer:

C
#define CURL_SB_ACCUM(x, c)                                   \
  do {                                                        \
    if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \
      *x->subpointer++ = (c);                                 \
  } while(0)

Line by line:

  • #define CURL_SB_ACCUM(x, c) starts the definition of a macro named CURL_SB_ACCUM that takes two things: x, the telnet state structure, and c, the byte to store.
  • do { ... } while(0) is a common C trick to wrap several statements so they behave like a single statement wherever the macro is used.
  • if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) is the safety check. x->subbuffer is the start of the 512-byte buffer, sizeof(x->subbuffer) is its size, so the sum is the address just past the end. The condition asks: is the current pointer still before that end address? In plain words: is there room?
  • *x->subpointer++ = (c); runs only if there is room. It stores the byte c at the place the pointer points to, then moves the pointer one position forward. The ++ after the pointer is what does the moving.

So the macro is careful: no room, no write, no movement.

In the CURL_TS_SE state handling, however, the pointer is moved back by two bytes unconditionally, after two CURL_SB_ACCUM calls that may both have been skipped because the buffer was full. There are two such paths.

CURL_TS_SE is the internal state meaning "we have just seen the end-of-subnegotiation marker". A state is simply a label the program keeps to remember where it is in a conversation, like a bookmark in a recipe.

Path 1 (lines 1207 to 1211):

C
CURL_SB_ACCUM(tn, CURL_IAC);
CURL_SB_ACCUM(tn, c);
tn->subpointer -= 2;    // UNCONDITIONAL - causes underflow when buffer is full
CURL_SB_TERM(tn);

Line by line:

  • CURL_SB_ACCUM(tn, CURL_IAC); tries to store the IAC marker byte in the buffer, using the safe macro above. If the buffer is full, nothing happens.
  • CURL_SB_ACCUM(tn, c); tries to store the byte c that followed the marker. Again, if the buffer is full, nothing happens.
  • tn->subpointer -= 2; moves the pointer back two positions, with no check at all. The comment in the code itself flags this as unconditional. The intent was to undo the two stores just made, because the terminating sequence should not be part of the collected data. But if the stores were skipped, there is nothing to undo, and the pointer moves back into invalid territory.
  • CURL_SB_TERM(tn); marks the end of the collected data, recording the current pointer as the end position. If the pointer is already wrong, the end marker is wrong too.

Path 2 (lines 1223 to 1227):

C
CURL_SB_ACCUM(tn, CURL_IAC);
CURL_SB_ACCUM(tn, CURL_SE);
tn->subpointer -= 2;    // UNCONDITIONAL - causes underflow when buffer is full
CURL_SB_TERM(tn);

Line by line:

  • CURL_SB_ACCUM(tn, CURL_IAC); tries to store the IAC marker, safely.
  • CURL_SB_ACCUM(tn, CURL_SE); tries to store the SE end marker, safely.
  • tn->subpointer -= 2; again moves the pointer back two positions without checking whether anything was written.
  • CURL_SB_TERM(tn); again records the end position from the possibly wrong pointer.

The asymmetry is the bug: the write is guarded by a bounds check, the pointer arithmetic that is meant to undo that write is not. When the buffer is full, nothing was written, but the pointer still moves backwards.

Exploitation

The exploitation flow, as described in the report:

  1. A malicious telnet server sends suboption data to fill the 512-byte buffer (SUBBUFSIZE).
  2. The server sends IAC followed by another byte while the buffer is full.
  3. The CURL_SB_ACCUM macro does nothing, because the buffer-full check fails.
  4. subpointer -= 2 executes unconditionally, causing the pointer to underflow.
  5. CURL_SB_TERM sets subend = subpointer, which now points before the start of the buffer.
  6. suboption() is called with the corrupted pointer.
  7. The CURL_SB_LEN macro calculates a negative or wrapped length.
  8. printsub() reads out-of-bounds memory in verbose mode.

In everyday terms: the attacker fills the tray completely, then sends two more control bytes. The safe macro refuses to put them anywhere, but the rollback still moves the finger two places left of the tray. The program then measures the distance between the finger and the end marker, gets a nonsensical (negative or wrapped-around) number, and reads that many bytes starting from the wrong place. SUBBUFSIZE is simply the name of the constant holding the buffer size, 512.

Step 1: save the PoC server

Save the attached PoC script as curl_telnet_poc.py.

The script is the Python PoC server attached to the report. You save it under that exact name because the next command refers to it by name. A server here means a program that waits for connections and talks to whoever connects.

Step 2: run the malicious telnet server

Bash
python3 curl_telnet_poc.py -p 2323

Line by line:

  • python3 runs the Python interpreter, the program that executes Python scripts.
  • curl_telnet_poc.py is the script you saved.
  • -p 2323 is the port argument used in the report's command. A port is like a numbered door on a computer; other programs knock on that door to reach the server. 2323 is the port number used in the report's command.

Run the PoC server with the command from the report. You run it first because the client needs something to connect to.

Step 3: connect with curl in verbose mode

In another terminal:

Bash
curl -v telnet://[redacted]:2323

Line by line:

  • curl is the program under test.
  • -v turns on verbose mode, which prints detailed information about the connection, including the suboption data. This flag is the whole point of the step: it is what causes printsub() to run and display the suboption data.
  • telnet:// tells curl to use its telnet handler rather than, say, HTTP.
  • [redacted] is the loopback address, meaning "this same computer".
  • :2323 is the port number, matching the one the server listens on.

The report says to run the curl command in another terminal.

Step 4: observe the output

Look in the verbose output for:

  • anomalous suboption data in the output;
  • potential non-printable characters indicating a memory leak;
  • a possible crash, depending on memory layout.

Why these signs: if the pointer went before the buffer, the program reads bytes that were never meant to be shown. Those bytes may look like garbage, may include characters your terminal cannot display, or may be bytes that happen to make the program fall over.

Step 5: confirm with AddressSanitizer

For better observation, build curl with ASan:

Bash
./configure CFLAGS="-fsanitize=address -g"
make
./src/curl -v telnet://[redacted]:2323

Line by line:

  • ./configure CFLAGS="-fsanitize=address -g" runs curl's configuration script, which prepares the build. CFLAGS passes extra options to the compiler. -fsanitize=address switches on AddressSanitizer, and -g keeps debugging information so error messages can point at source lines.
  • make compiles the program according to the configuration just prepared.
  • ./src/curl -v telnet://[redacted]:2323 runs the freshly built curl from the src directory with the same verbose telnet connection as before.

ASan should report an out-of-bounds read. The report says building with ASan gives better observation.

Root cause

The CURL_SB_ACCUM macro is safe on its own: it checks x->subpointer < (x->subbuffer + sizeof(x->subbuffer)) before writing and advancing. The CURL_TS_SE handlers assume that the two preceding CURL_SB_ACCUM calls always advanced the pointer by two, and undo them with tn->subpointer -= 2. When the buffer is full, both accumulations are skipped, so the decrement moves the pointer two bytes before the start of subbuffer. CURL_SB_TERM then records that out-of-bounds position as subend, and the subsequent suboption() and printsub() calls work with a length derived from the corrupted pointers.

In short: one piece of code is defensive, the other trusts it blindly. The rollback assumes success without checking whether success happened.

The memory layout of struct TELNET explains what sits in front of the buffer:

C
struct TELNET {
  // ... other fields ...
  struct dynbuf out;              // Contains heap pointers
  unsigned char subbuffer[512];   // The suboption buffer
  unsigned char *subpointer;      // Points into subbuffer
  unsigned char *subend;          // End marker
  // ...
};

Line by line:

  • struct TELNET { ... }; declares a structure, which in C is a bundle of related variables stored together in memory, one after another. Think of it as a form with several fields.
  • struct dynbuf out; is a field named out of type dynbuf, a curl type for a growable buffer. Its comment says it contains heap pointers. The heap is the general-purpose pool of memory a program uses for data created while it runs.
  • unsigned char subbuffer[512]; is the fixed 512-byte array where suboption bytes are collected.
  • unsigned char *subpointer; is the moving pointer into that array.
  • unsigned char *subend; marks where the collected data ends.

When subpointer underflows, it points into the dynbuf out structure that precedes subbuffer, which contains heap pointers that may be leaked.

Impact

The report rates the issue as low severity and lists two effects.

  1. Information disclosure (low to medium). In verbose mode, printsub() may read and display memory from before the suboption buffer. This could potentially leak heap pointers (useful for an ASLR bypass in chained exploits), the contents of the dynbuf out structure, and other sensitive data in adjacent memory.
  2. Denial of service (low). Depending on memory layout and access patterns, the out-of-bounds read could cause a crash.

Terms here:

  • Information disclosure: a bug that reveals data the program did not intend to show.
  • ASLR (Address Space Layout Randomisation): an operating system defence that places memory at unpredictable addresses each time a program runs, so an attacker cannot hard-code addresses. A leaked pointer tells the attacker where things actually are, which weakens that defence.
  • Chained exploits: attacks that combine several bugs, where one bug provides a piece of information needed by the next.
  • Denial of service: making a program or service stop working, for example by crashing it.
  • Memory layout: the order and positions in which the program's data ends up in memory.

The attack scenario: an attacker controlling a malicious telnet server waits for a victim to connect with curl -v telnet://malicious-server, sends crafted suboption data to trigger the vulnerability, and may then observe leaked memory contents in error messages or logs, using leaked heap pointers to aid in exploiting other vulnerabilities.

The report is explicit about the limits: the victim must connect to an attacker-controlled telnet server, the issue is most impactful in verbose mode (-v), the telnet protocol is deprecated and rarely used, and there is no direct code execution capability.

"No direct code execution" means the bug by itself cannot make the attacker's code run on the victim's machine. It only reveals memory or crashes the program. The report lists no direct code execution capability as a limitation.

Fix

The report does not describe a fix or a patch.

In the pigeonhole comparison: the clerk should only step back for letters actually placed in holes. If nothing was placed, the finger stays where it is.

Variants to test

These are follow-up ideas for someone hunting similar bugs elsewhere. Each one is a variation on the same theme: a check in one place and unchecked arithmetic in another.

  • Other fixed-size accumulation buffers with a matching rollback. Look for macros or helpers that guard a write with a bounds check but pair it with unconditional pointer arithmetic elsewhere. A positive result is a path where the pointer can be moved before the buffer start while the write was skipped.
  • Other telnet state transitions. The report covers the CURL_TS_SE state. Exercise the other states that use CURL_SB_ACCUM, CURL_SB_TERM, CURL_SB_GET and CURL_SB_LEN with a full buffer and watch for lengths that wrap or go negative.
  • Verbose and non-verbose runs. Run the same PoC with and without -v under ASan. A positive result is an out-of-bounds read report in one mode and not the other, which tells you which code path consumes the corrupted pointers.
  • Buffer boundary sizes. Fill the buffer to exactly SUBBUFSIZE and then send the terminating sequence, rather than overfilling it, to see whether the off-by-two rollback alone is enough to underflow.
  • Other curl protocol handlers with fixed buffers. Apply the same reasoning to any handler that keeps a pointer into a fixed array and adjusts it after conditional writes; a positive result is any read whose start address precedes the array.

A "wrapped" length means a number that went below zero and, because of how computers store numbers, turned into a very large positive one.

Glossary

  • AddressSanitizer (ASan): a compiler feature that watches a running program and reports reads or writes outside valid memory.
  • ASLR (Address Space Layout Randomisation): an operating system defence that randomises where memory is placed, so leaked addresses are valuable to an attacker.
  • Buffer: a reserved area of memory used to hold data temporarily.
  • Buffer underflow: moving a pointer below the start of the area it should stay in.
  • Code execution: the ability for an attacker to make their own instructions run on the victim's machine.
  • curl: a command-line program for transferring data over many network protocols, including telnet.
  • dynbuf: a curl type for a growable buffer, used for data whose size is not known in advance.
  • Handler: the part of a program that deals with one particular protocol or feature.
  • Heap: the general-purpose pool of memory a program uses for data created while it runs.
  • IAC, SB, SE: telnet control bytes. IAC marks a command, SB starts a subnegotiation, SE ends it.
  • Loopback address ([redacted]): the address meaning "this same computer".
  • Macro: a named snippet of code that the compiler expands wherever the name appears.
  • Memory layout: the order and positions in which a program's data ends up in memory.
  • Memory leak (in this context): memory contents being revealed to someone who should not see them.
  • PoC (proof of concept): a small program that demonstrates a bug is real.
  • Port: a numbered door on a computer that programs use to reach a service.
  • Precondition: something that must be true before a bug can be triggered.
  • Source code: the human-readable text a program is built from.
  • State: a label a program keeps to remember where it is in a conversation or process.
  • struct: a C construct that bundles several related variables together in memory.
  • Suboption: a small telnet control message used to negotiate extra features.
  • Telnet: an old text-terminal protocol for connecting to remote machines.
  • Verbose mode (-v): a switch that makes a program print detailed diagnostic information.
  • Wrapped length: a number that went below zero and turned into a very large positive one because of how computers store numbers.

More by stif

View all

1 more disclosed report, best first.

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.