Opened 4 years ago

Closed 4 years ago

#1021 closed defect (fixed)

non-POD types passed to .../va_start is UB

Reported by: gdt Owned by: strk
Priority: minor Milestone: 3.8.2
Component: C API Version: 3.8.0
Severity: Unassigned Keywords:
Cc:

Description

In capi/geos_ts_c.cpp, the NOTICE and ERROR functions are variadic and take a std::string as the first argument. They then call va_start with this non-POD type. This lands us in "conditionally defined" behavior (5.2.2 clause 7), which given multiple possible compilers is really "undefined behavior". Some links which help explain why this is a painful situation.

I have attached a patch which avoids the issue, essentially by hoisting the c_str() before the call (and making it implicit). With this patch and 3.8.1, tests pass on NetBSD 8 amd64 and macOS 10.13 amd64.

Attachments (1)

patch-capi_geos__ts__c.cpp (1.7 KB ) - added by gdt 4 years ago.

Download all attachments as: .zip

Change History (6)

by gdt, 4 years ago

Attachment: patch-capi_geos__ts__c.cpp added

comment:1 by gdt, 4 years ago

Milestone: 3.9.03.8.1

This might as well be fixed in 3.8.2 as well as master; picking 3.8.1 as meaning 3.8.2.

comment:2 by pramsey, 4 years ago

Milestone: 3.8.13.8.2

comment:4 by pramsey, 4 years ago

Huh, I actually have a unit test failure on OSX, with this patch still.

Darwin Kernel Version 19.4.0
MacOS 10.15

CI seems has come up green though...

comment:5 by Paul Ramsey <pramsey@…>, 4 years ago

Resolution: fixed
Status: newclosed

In e6f315d/git:

Remove undefined behaviour in CPI, closes #1021

Note: See TracTickets for help on using tickets.