MDSplus / mdsplus

The MDSplus data management system
https://mdsplus.org/
Other
72 stars 44 forks source link

mdsplus8 and alpha: the "dir" command of "mdstcl" crashes when working with deep trees that have long paths #2654

Open mwinkel-dev opened 11 months ago

mwinkel-dev commented 11 months ago

Affiliation MIT PSFC

Version(s) Affected Alpha and also mdsplus8 (probably all other versions too)

Platform Ubuntu 20.04 but probably exists on all other platforms

Describe the bug Was working with a tree that had more than 13 levels of hierarchy and thus the full path of nodes was 110+ characters. Conjecture is that the full path is exceeding the width of the output buffer (which might be 128 characters?).

Note that this will be an issue when using mdsplus8 to navigate through trees that are named with IMAS / OMAS conventions. (IMAS and OMAS have many levels of hierarchy and long node names.)

To Reproduce Steps to reproduce the behavior:

  1. Create a tree that has 10 levels of hierarchy with each node name 12 characters in length.
  2. Use mdstcl to open the tree
  3. Type dir *** and notice the error about the buffer overflow.
  4. Alternatively, navigate down to the 9th level of the tree using the set default command, and then type dir.

Here is sample output from step 4.

$ mdstcl
TCL> edit junk /shot=123 /new
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL>    set def a23456789012
TCL> add node a23456789012 /usage=structure
TCL> write
TCL> dir
*** buffer overflow detected ***: terminated
zsh: abort (core dumped)  mdstcl
$ 

Expected behavior The dir command of mdstcl should not crash on paths of ~120 characters or so. Yes, it makes sense to limit the width of the output buffer, but it should probably be increased to 512 or 1024 characters.

Screenshots n/a

Additional context This should definitely be fixed in mdsplus8 (which supports 63 character node names), because mdsplus8 will likely be used with the IMAS and OMAS path names (which are quite long).

And perhaps should also be fixed in alpha, especially if some customers will be abbreviating IMAS and OMAS names to fit into 12 character node names.

Other tools (jTraverser, etc.) should also be checked to see if they can handle trees with long full paths.

mwinkel-dev commented 10 months ago

Additional testing indicates that the buffer overflow occurs when the full path (less the leaf node) is 125 visible characters. (There are also some new line characters, thus the total output message exceeds 128 characters.)

mwinkel-dev commented 10 months ago

Investigation reveals that there are two bugs in the tcl/tcl_directory.c file.

The buffer overflow occurs when the path length (plus new line characters) exceeds the msg buffer size. This buffer should be increased in both branches: alpha and mdsplus8.
line 177

In the mdsplus8 branch, there is an additional problem because the node name size is specified incorrectly. The node names only have 63 visible characters (i.e., the trailing null character should not be included). line 133 line 138

mwinkel-dev commented 10 months ago

Clarification: IMAS and OMAS are abstraction layers above MDSplus and other data stores. Thus, it is unlikely that full IMAS and OMAS paths will be mirrored directly in MDSplus.

However, when designing new MDSplus trees, it is possible that some nodes in the tree will use similar names in order to simplify the mapping from MDSplus to IMAS / OMAS. Thus, those new trees will likely encounter this mdstcl buffer overflow bug.