Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asn1: unmarshalling strings in structs fails #516

Closed
taruti opened this issue Jan 11, 2010 · 4 comments
Closed

asn1: unmarshalling strings in structs fails #516

taruti opened this issue Jan 11, 2010 · 4 comments

Comments

@taruti
Copy link
Contributor

taruti commented Jan 11, 2010

Trying to unmarshal a struct containing a string field fails on recent hg
checkout on 386-linux. Below is code demonstrating this:


package main

import "asn1"
import "bytes"
import "io/ioutil"

type Ok    struct { A, B int }
type Fails struct { S string; A, B int }

func main() {
    var ok Ok
    var fails Fails

    // This is ok
    buf := bytes.NewBuffer(nil)
    if e := asn1.Marshal(buf, Ok{0x22,0x33}); e!=nil {
        panic("Marshal")
    }
    if _, e := asn1.Unmarshal(&ok, buf.Bytes()); e!=nil {
        panic("Unmarshal")
    }

    // Now try it with a structure containing a string
    buf = bytes.NewBuffer(nil)
    if e := asn1.Marshal(buf, Fails{"foo", 0x22,0x33}); e!=nil {
        panic("Marshal2")
    }
    // write it to a file where it can be inspected, try with:
    // openssl asn1parse -inform DER -in /tmp/asn1.der
    ioutil.WriteFile("/tmp/asn1.der", buf.Bytes(), 0644)

    // The bug is here - this fails!
    if _, e := asn1.Unmarshal(&fails, buf.Bytes()); e!=nil {
        panic("Unmarshal2")
    }

}
@taruti
Copy link
Contributor Author

taruti commented Jan 11, 2010

Comment 1:

Note that the marshalling won't work properly either unless the patch in issue #515 is
already aplied. It is not a bug in the marshalling patch as can be seen with dumping
the values with external tools.

@rsc
Copy link
Contributor

rsc commented Jan 11, 2010

Comment 2:

Owner changed to a...@golang.org.

@agl
Copy link
Contributor

agl commented Jan 12, 2010

Comment 3:

http://golang.org/cl/184080

Status changed to Started.

@agl
Copy link
Contributor

agl commented Jan 12, 2010

Comment 4:

This issue was closed by revision 72b97e4.

Status changed to Fixed.

Merged into issue #-.

@taruti taruti added the fixed label Jan 12, 2010
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants