safchain / ethtool

A simple ethtool "like" library for GO
Apache License 2.0
120 stars 69 forks source link

DriverInfo.Version contains NULL followed by garbage #39

Closed bdrung closed 3 years ago

bdrung commented 3 years ago

The version for bridge and tun devices is reported incorrectly. The code from the example:

    e, err := ethtool.NewEthtool()
    if err != nil {
        panic(err.Error())
    }
    defer e.Close()

    drvInfo, err := e.DriverInfo(*name)
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("drvrinfo: %+v\n", drvInfo)

returns:

$ ./example -interface br0
drvrinfo: {Cmd:3 Driver:bridge Version:2.3.0-22-generic FwVersion:N/A BusInfo:N/A EromVersion: Reserved2: NPrivFlags:0 NStats:0 TestInfoLen:0 EedumpLen:0 RegdumpLen:0}

Hexdump shows that the version 2.3.0-22-generic contains a NULL character after 2.3. ethtool correctly reports the version:

$ ethtool -i br0
driver: bridge
version: 2.3
firmware-version: N/A
expansion-rom-version:
bus-info: N/A
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
$ ethtool -i tun0
driver: tun
version: 1.6
firmware-version:
expansion-rom-version:
bus-info: tun
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no