Skip to content

Incorrect CAPA termination detection #19228

Closed

Description

@MegaManSec

I did this

The CAPA response termination check treats any line that begins with '.' as the terminating line rather than requiring a single '.' line. According to POP3 multi-line response rules, the terminator is a line consisting of only a single dot ("."), so a line like ".capability" would be misinterpreted as the end of the CAPA response. This can cause premature termination of capability parsing and missing or incorrect capability handling.

The affected code is here:

curl/lib/pop3.c

Lines 324 to 334 in f4293cd

/* Are we processing CAPA command responses? */
if(pop3c->state == POP3_CAPA) {
/* Do we have the terminating line? */
if(len >= 1 && line[0] == '.')
/* Treat the response as a success */
*resp = '+';
else
/* Treat the response as an untagged continuation */
*resp = '*';
return TRUE;

From https://www.rfc-editor.org/rfc/rfc1939: "When all lines of the response have been sent, a final line is sent, consisting of a termination octet '.' and a CRLF pair"
From https://datatracker.ietf.org/doc/html/rfc2449: "The capability list is terminated by a line containing a termination octet '.' and a CRLF pair"

This bug was found with ZeroPath.

I expected the following

No response

curl/libcurl version

newest

operating system

all

Activity

  1. added a commit that references this issue on Oct 26, 2025
    7a63d23
  2. thebitbrine commented on Oct 26, 2025

    @thebitbrine
    Contributor

    Found the issue and put up a fix in #19245.

    The problem's in pop3_endofresp() it's checking len >= 1 && line[0] == '.' which matches any line starting with a dot, not just the terminator. RFC 2449 says the terminator has to be a line with only a single dot.

    Changed it to check for exact match: length 3 with .\r or length 2 with .\n (to handle LF-only servers) similar to how IMAP does continuation checks.

    Ran all 37 POP3 tests, everything passes. The bug's theoretical anyway since capability names can't start with . per the RFC, but might as well get it right.

  3. added a commit that references this issue on Oct 26, 2025
    a49e4e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions