-
Notifications
You must be signed in to change notification settings - Fork 28
Description
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:
- 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
:
- Look at the file from linux
:!vdir BP
total 4
-rw-r--r-- 1 mabull mabull 21 Sep 12 12:18 %t
:
- 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
:
- 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]));