Skip to content

BASIC command SSELECT on directory file with item %t segfaults #85

@mbullr

Description

@mbullr

The BASIC command SSELECT will segfault when processing a directory file with a item id of "%chr", where chr is any character not found in df_substitute_chars "ACEGLPSVXYZBQ" as defined in qm.h, or the letters "T" and "D".

This is actually a multi part issue.

op_dio4.c dir_select () - Perform select on a directory file
This routine converts mapped names for upper case T, D and for the characters found in df_substitute_chars.
If the character following the "%" character does not meet the above, a null valued btree entry will be created for the file name.

op_sort.c / op_sortdata() SSELECT operation
When processing the btree items created from the list created by dir_select, the code performs a strlen function call on the item. On the null items this causes a segfault.

op_dio3.c map_t1_id() - Perform name mapping for directory files
Maps "~" to "%t"
Maps "." to "%d"
This is inconsistent with the mapping performed in dir_select

The following demonstrates the issue:

  1. Add tilde file id to BP via editor

:ED BP ~
BP ~
New record
----: I
0001= this is a tilde test
0002=
Bottom at line 1
----: fi
'~' filed in BP
:sort only BP
0 record(s) listed
:

  1. Look at the file from linux

:!vdir BP
total 4
-rw-r--r-- 1 mabull mabull 21 Sep 12 12:18 %t
:

  1. Add the following program to BP:

PROGRAM TILDE_TEST

  • TEST FIX FOR SSELECT / OP_SORT.C
  • ASSUMES DIRECTORY FILE BP HAS ITEM NAMED "%t"
    OPEN "BP" TO BP.FV ELSE ABORT "CANNOT OPEN BP"

SSELECT BP.FV TO 2
*
DONE = @false
LOOP
WHILE NOT(DONE)
READNEXT ID FROM 2 THEN
CRT "ID: ":ID
END ELSE
DONE = @true
END
REPEAT
CRT "ALL DONE"
END

sort only BP Page 1
BP..........
tilde_test

1 record(s) listed
:

From linux:
:!vdir BP
total 8
-rw-r--r-- 1 mabull mabull 21 Sep 12 12:18 %t
-rw-r--r-- 1 mabull mabull 311 Sep 12 12:22 tilde_test
:

  1. Run the test program
    :RUN BP tilde_test
    Fault type 11. PC = 000000DF (CF 4A) in SSELCT
    Errno : 00000002
    4 16E92CF8: 00 00 00000000 00000000
    3 16E92CE0: 02 00 00000000 00000000
    2 16E92CC8: 02 00 00000000 00000000
    1 16E92CB0: 02 00 00000001 00000000
    0 16E92C98: 02 04 00000002 00000000
    -1 16E92C80: 01 00 16E7EA88 00000000
    Segmentation fault (core dumped)

To prevent the segfault, modify op_sort.c as follows:

op_sort.c
ln 584 change to:
if (bte->key[0] != NULL)
ts_copy(bte->key[0], strlen(bte->key[0]));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions