Skip to content

Fix crash when server give no status.#77

Open
hugopl wants to merge 1 commit into
arcage:masterfrom
hugopl:fix-crash
Open

Fix crash when server give no status.#77
hugopl wants to merge 1 commit into
arcage:masterfrom
hugopl:fix-crash

Conversation

@hugopl

@hugopl hugopl commented Jan 31, 2026

Copy link
Copy Markdown

When trying to send a email to smtp4dev running in a docker compose like:

  smtp:
    image: rnwood/smtp4dev:v3
    ports:
      - '127.0.0.1:5000:80'    # Localhost only
      - '127.0.0.1:2525:2525'    # Localhost only
    volumes:
      - ./docker-data/smtp4dev:/smtp4dev
    environment:
      #Specifies the URLs the web UI will use inside the container.
      - ServerOptions__Urls=http://*:80
      #Specifies the server hostname. Used in auto-generated TLS certificate if enabled.
      - ServerOptions__HostName=smtp
      #Specifies the TLS mode to use. None=Off. StartTls=On demand if client supports STARTTLS. ImplicitTls=TLS as soon as connection is established.
      - ServerOptions__TlsMode=StartTls
      #Uncomment to disable IPv6 if your Docker environment doesn't support it (helps avoid startup errors in some Docker configurations)
      - ServerOptions__DisableIPv6=true
      #Specifies a mailbox with name "Test" and recipient "hello@world.com". To add more, use the same format but replace the number at the end of the variable name.
      - ServerOptions__Mailboxes__0=Test=test@test.com
      - ServerOptions__AuthenticationRequired=true

It crashes with:

Index out of bounds (IndexError)
  from /opt/homebrew/Cellar/crystal/1.19.1/share/crystal/src/string.cr:805:22 in '[]'
  from lib/email/src/email/client.cr:236:10 in 'smtp_responce'
  from lib/email/src/email/client.cr:110:22 in 'perform'

This patch fixes this crash.

When trying to send a email to smtp4dev running in a docker compose
like:

```
  smtp:
    image: rnwood/smtp4dev:v3
    ports:
      - '127.0.0.1:5000:80'    # Localhost only
      - '127.0.0.1:2525:2525'    # Localhost only
    volumes:
      - ./docker-data/smtp4dev:/smtp4dev
    environment:
      #Specifies the URLs the web UI will use inside the container.
      - ServerOptions__Urls=http://*:80
      #Specifies the server hostname. Used in auto-generated TLS certificate if enabled.
      - ServerOptions__HostName=smtp
      #Specifies the TLS mode to use. None=Off. StartTls=On demand if client supports STARTTLS. ImplicitTls=TLS as soon as connection is established.
      - ServerOptions__TlsMode=StartTls
      #Uncomment to disable IPv6 if your Docker environment doesn't support it (helps avoid startup errors in some Docker configurations)
      - ServerOptions__DisableIPv6=true
      #Specifies a mailbox with name "Test" and recipient "hello@world.com". To add more, use the same format but replace the number at the end of the variable name.
      - ServerOptions__Mailboxes__0=Test=test@test.com
      - ServerOptions__AuthenticationRequired=true
```

It crashes with:

```
Index out of bounds (IndexError)
  from /opt/homebrew/Cellar/crystal/1.19.1/share/crystal/src/string.cr:805:22 in '[]'
  from lib/email/src/email/client.cr:236:10 in 'smtp_responce'
  from lib/email/src/email/client.cr:110:22 in 'perform'
```

This patch fixes this crash.
@hugopl

hugopl commented Jan 31, 2026

Copy link
Copy Markdown
Author

BTW, the connection error is because the client didn't use the right certificates, besides the wrong port 😅 , anyway still a fix since this can't crash, but error out.

@arcage

arcage commented Feb 1, 2026

Copy link
Copy Markdown
Owner

Thank you very much for your contribution!

Regarding this PR, I would like to clarify the specific situation where the "server give no status". Based on the current design, the library is intended to raise an exception if the reply code is missing from the server's response.

To help me understand the issue better, could you show the specific command/reply sequence where the server returns no status?

I'd like to understand the exact scenario where the execution reaches line 231 while status_code is still empty.

I want to ensure we handle this protocol violation in a way that remains compliant with RFC 5321 while preventing crashes. Looking forward to your reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants