Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(705)

Issue 96790047: cmd/cgo: fix C.CString for strings containing null term... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years ago by pcc
Modified:
10 years, 11 months ago
Reviewers:
iant, ioe
CC:
iant, golang-codereviews_google.com, golang-codereviews
Visibility:
Public.

Description

cmd/cgo: fix C.CString for strings containing null terminators under gccgo Previously we used strndup(3) to implement C.CString for gccgo. This is wrong because strndup assumes the string to be null terminated, and stops at the first null terminator. Instead, use malloc and memmove to create a copy of the string, as we do in the gc implementation.

Patch Set 1 #

Patch Set 2 : diff -r e141dda580af https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+4 lines, -1 line) Patch
M src/cmd/cgo/out.go View 1 1 chunk +4 lines, -1 line 0 comments Download

Messages

Total messages: 5
pcc
11 years ago (2014-04-27 04:06:19 UTC) #1
iant
LGTM
11 years ago (2014-04-27 05:16:21 UTC) #2
iant
*** Submitted as https://code.google.com/p/go/source/detail?r=6cf757123ad4 *** cmd/cgo: fix C.CString for strings containing null terminators under gccgo ...
11 years ago (2014-04-27 05:16:41 UTC) #3
ioe
I agree that this is a nice security stop gap, but wouldn't a behavior similar ...
11 years ago (2014-04-27 15:17:07 UTC) #4
iant
11 years ago (2014-04-27 16:23:54 UTC) #5
On Apr 27, 2014 9:17 AM, <nightlyone@googlemail.com> wrote:
>
> I agree that this is a nice security stop gap, but
> wouldn't a behavior similar to syscall.BytePtrFromString() be more useful
here?
>
> That way the caller has a chance to find the now existing issue (zero in
middle of a zero terminated string) via testing.

Unlike the syscall package, we don't know the API here.  The length may be
passed separately.  In any case, this CL just makes gccgo act like gc.

Ian

> On Sunday, April 27, 2014 7:16:41 AM UTC+2, Ian Lance Taylor wrote:
> > *** Submitted as
> >
> > https://code.google.com/p/go/source/detail?r=6cf757123ad4 ***
> >
> >
> >
> > cmd/cgo: fix C.CString for strings containing null terminators under
> >
> > gccgo
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b