Skip to content

parsedate: validate NULL date pointer in curl_getdate - #23156

Closed
filtede98 wants to merge 1 commit into
curl:masterfrom
filtede98:fix-parsedate-null-pointer-guards
Closed

filtede98 wants to merge 1 commit into
curl:masterfrom
filtede98:fix-parsedate-null-pointer-guards

Conversation

@filtede98

@filtede98 filtede98 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Calling curl_getdate() with a NULL date pointer unconditionally dereferenced the pointer in parsedate() at while(*date && (part < 6)), causing a crash.

This change hardens the public API entry point:

  1. curl_getdate() validates that p is non-NULL and immediately returns -1, matching its documented error return code for unparseable dates.
  2. Unit test lib517 is extended to verify curl_getdate(NULL, NULL) == -1.
  3. The curl_getdate documentation is updated to specify the -1 return code on NULL input.

Signed-off-by: Filippo Tedeschi filippotedeschi98@gmail.com

Comment thread lib/parsedate.c Resolved
Comment thread lib/parsedate.c Resolved
@vszakats

vszakats commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Are these internal functions ever called with a NULL from curl code?

Would it be enough to protect against these at the public interface
points, in this case in curl_getdate()?

It can be "defense in depth" if the project decided to go with this
pattern, but adding such checks in a mechanical way to internal
functions seems overkill to me.

@filtede98
filtede98 force-pushed the fix-parsedate-null-pointer-guards branch from 9dd7817 to 2ec5c5f Compare September 29, 2026 08:48
@filtede98 filtede98 changed the title parsedate: validate NULL date and output pointers in curl_getdate and helpers parsedate: validate NULL date pointer in curl_getdate Sep 29, 2026
@filtede98

Copy link
Copy Markdown
Contributor Author

@vszakats Thank you for the feedback. That makes complete sense.

I have updated the PR to focus strictly on the public entry point:

  1. Validating !p in curl_getdate() and returning -1 immediately.
  2. Reverting changes to internal helpers (checkday, checkmonth, checktz, parsedate, Curl_getdate_capped).
  3. Retaining unit test coverage in tests/libtest/lib517.c and updating docs/libcurl/curl_getdate.md.

Comment thread tests/libtest/lib517.c Resolved
@jay

jay commented Sep 29, 2026

Copy link
Copy Markdown
Member
  1. Validating !p in curl_getdate() and returning -1 immediately.

Sure I think that's fine. I don't think it needs to be documented though.

@filtede98
filtede98 force-pushed the fix-parsedate-null-pointer-guards branch from 2ec5c5f to d3bdb14 Compare September 30, 2026 15:47
@filtede98

Copy link
Copy Markdown
Contributor Author

Updated: cast the return check to (time_t)-1 in lib517.c to prevent platform signedness warnings on AmigaOS/MS-DOS, and reverted the documentation change in curl_getdate.md. Rebased cleanly on latest master.

Comment thread lib/parsedate.c Resolved
@filtede98
filtede98 force-pushed the fix-parsedate-null-pointer-guards branch from d3bdb14 to 55e0b93 Compare September 30, 2026 17:04
@filtede98

Copy link
Copy Markdown
Contributor Author

Good catch, removed the blank line. Thank you @vszakats!

Comment thread lib/parsedate.c Resolved
Calling curl_getdate() with a NULL date pointer unconditionally dereferenced
the pointer in parsedate() at while(*date && (part < 6)), causing an immediate
crash.

This change hardens the public entry point:
1. curl_getdate() checks for NULL input and returns -1 immediately, matching
   its documented error return code for unparseable dates.
2. Unit test lib517 is extended to verify NULL pointer safety across all platforms.

Signed-off-by: Filippo Tedeschi <filippotedeschi98@gmail.com>
@filtede98
filtede98 force-pushed the fix-parsedate-null-pointer-guards branch from 55e0b93 to 302372f Compare September 30, 2026 18:03
@filtede98

Copy link
Copy Markdown
Contributor Author

Ah, understood! Updated to keep the newline above rc = and deleted the one after, so rc = parsedate(p, &parsed); and if(rc == PARSEDATE_OK) are grouped together. Thank you @vszakats!

@jay jay closed this in ff1fa03 Oct 1, 2026
@jay

jay commented Oct 1, 2026

Copy link
Copy Markdown
Member

Thanks

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

Development

Successfully merging this pull request may close these issues.

3 participants