libbsd setmode/getmode give unexpected mode_t value possibly due to uninitialised value
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
libbsd (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Consider the following code from the implementation (InstallCmd()) of a Tcl extension function "xinstall" that mimics the /usr/bin/install command:
case 'm': {
if (!objc) {
}
const char *modeString = Tcl_GetString(
if (!(set = setmode(
}
mode = getmode(set, 0);
if (verbose) {
}
objv++, objc -= 2;
break;
}
I use this function in a Tcl-based build/packaging
When calling this as `xinstall -v -m 775 -d foo`there are intermittent conditions ("episodes") under which I see
```
:debug:destroot xinstall: mode=775 umask=0225
:error:destroot Failed to destroot qt5-kde-angel: error renaming "/opt/local/
```
and valgrind reports
```
==20578== 46 errors in context 11 of 13:
==20578== Conditional jump or move depends on uninitialised value(s)
==20578== at 0x77CD81C: getmode (setmode.c:123)
==20578== by 0x77D240B: InstallCmd (xinstall.c:254)
==20578== by 0x4E6E2B5: TclEvalObjvInternal (tclBasic.c:3727)
==20578== by 0x4EB4F8A: TclExecuteByteCode (tclExecute.c:2414)
==20578== by 0x4EB8D6A: TclCompEvalObj (tclExecute.c:1535)
==20578== by 0x4E6FDE8: TclEvalObjEx (tclBasic.c:5296)
==20578== by 0x4EF2670: Tcl_UplevelObjCmd (tclProc.c:945)
==20578== by 0x4E6E2B5: TclEvalObjvInternal (tclBasic.c:3727)
==20578== by 0x4EB4F8A: TclExecuteByteCode (tclExecute.c:2414)
==20578== by 0x4EF2F69: TclObjInterpPro
==20578== by 0x4E6E2B5: TclEvalObjvInternal (tclBasic.c:3727)
==20578== by 0x4EB4F8A: TclExecuteByteCode (tclExecute.c:2414)
==20578== Uninitialised value was created by a heap allocation
==20578== at 0x4C2AB80: malloc (in /usr/lib/
==20578== by 0x77CD93F: setmode (setmode.c:218)
==20578== by 0x77D23F5: InstallCmd (xinstall.c:246)
==20578== by 0x4E6E2B5: TclEvalObjvInternal (tclBasic.c:3727)
==20578== by 0x4EB4F8A: TclExecuteByteCode (tclExecute.c:2414)
==20578== by 0x4EB8D6A: TclCompEvalObj (tclExecute.c:1535)
==20578== by 0x4E6FDE8: TclEvalObjEx (tclBasic.c:5296)
==20578== by 0x4EF2670: Tcl_UplevelObjCmd (tclProc.c:945)
==20578== by 0x4E6E2B5: TclEvalObjvInternal (tclBasic.c:3727)
==20578== by 0x4EB4F8A: TclExecuteByteCode (tclExecute.c:2414)
==20578== by 0x4EF2F69: TclObjInterpPro
==20578== by 0x4E6E2B5: TclEvalObjvInternal (tclBasic.c:3727)
```
This error tends to go away after having tried various approaches to avoid it, which hints at the effects of an uninitialised variable, or a bounds-overwrite, hence running the script through valgrind.
Ubuntu 14.04 is still at libbsd 0.6 so I backported the latest available packaging from Launchpad (0.8.3-1). Initial results are encouraging: valgrind no longer complains about setmode or getmode called from InstallCmd().
I'd like to urge you to provide an official backport of this package; the process is trivial (see my ppa:rjvbertin/misc archive).