[asterisk-bugs] [JIRA] (ASTERISK-26481) FILE function grabs garbage along with read data when target line has no newline

Jonathan Harris (JIRA) noreply at issues.asterisk.org
Tue Oct 29 04:48:40 CDT 2019


    [ https://issues.asterisk.org/jira/browse/ASTERISK-26481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=248572#comment-248572 ] 

Jonathan Harris commented on ASTERISK-26481:
--------------------------------------------

October 2019, Asterisk 17.0, this is still happening

File is a single line unix encoded file, with  "1," (no quote marks)

hexdump output is as follows (sorry, no idea why code blocks aren't working)

```
0000000 2c31
0000002
```

dialplan is

```
    same => n(skipto),Set(unfilteredfeat=${FILE(${scanPath}/skipto.txt,0,1,l,u)})
    same => n,Set(feature=${SHIFT(unfilteredfeat)})
    same => n,Verbose(1,feature is ${feature} unfilteredfeat is ${unfilteredfeat})
```

Console log output is

```
    -- Executing [s at root:40] Set("Local/s at root-00000011;2", "unfilteredfeat=1,▒=") in new stack
[Oct 29 09:36:15] ERROR[2134][C-00000012]: json.c:607 ast_json_vpack: Error building JSON from '{s: s, s: s}': Invalid UTF-8 string.
[Oct 29 09:36:15] ERROR[2134][C-00000012]:   Got 11 backtrace records
# 0: /usr/sbin/asterisk(ast_json_pack+0xa5) [0x5627588a7f45]
# 1: /usr/sbin/asterisk(ast_channel_publish_varset+0x30) [0x562758937820]
# 2: /usr/sbin/asterisk(pbx_builtin_setvar_helper+0x148) [0x5627588e8e78]
# 3: /usr/sbin/asterisk(pbx_builtin_setvar+0x119) [0x5627588e9209]
# 4: /usr/sbin/asterisk(pbx_exec+0x158) [0x5627588dedf8]
# 5: /usr/sbin/asterisk(+0x137479) [0x5627588d3479]
# 6: /usr/sbin/asterisk(+0x139134) [0x5627588d5134]
# 7: /usr/sbin/asterisk(+0x13a7a1) [0x5627588d67a1]
# 8: /usr/sbin/asterisk(+0x1bd598) [0x562758959598]
# 9: /lib/x86_64-linux-gnu/libpthread.so.0(+0x9669) [0x7fa95fd1b669]
#10: /lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7fa95fa9f323]

[Oct 29 09:36:15] ERROR[2134][C-00000012]: stasis_channels.c:1161 ast_channel_publish_varset: Error creating message
[Oct 29 09:36:15] ERROR[2134][C-00000012]: json.c:607 ast_json_vpack: Error building JSON from '{s: s, s: s}': Invalid UTF-8 string.
[Oct 29 09:36:15] ERROR[2134][C-00000012]:   Got 12 backtrace records
# 0: /usr/sbin/asterisk(ast_json_pack+0xa5) [0x5627588a7f45]
# 1: /usr/sbin/asterisk(ast_channel_publish_varset+0x30) [0x562758937820]
# 2: /usr/sbin/asterisk(pbx_builtin_setvar_helper+0x148) [0x5627588e8e78]
# 3: /usr/lib/asterisk/modules/func_strings.so(+0x64c0) [0x7fa93fd054c0]
# 4: /usr/sbin/asterisk(ast_func_read+0x326) [0x5627588e35b6]
# 5: /usr/sbin/asterisk(pbx_substitute_variables_helper_full+0x282) [0x5627588e7cc2]
# 6: /usr/sbin/asterisk(+0x137445) [0x5627588d3445]
# 7: /usr/sbin/asterisk(+0x139134) [0x5627588d5134]
# 8: /usr/sbin/asterisk(+0x13a7a1) [0x5627588d67a1]
# 9: /usr/sbin/asterisk(+0x1bd598) [0x562758959598]
#10: /lib/x86_64-linux-gnu/libpthread.so.0(+0x9669) [0x7fa95fd1b669]
#11: /lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7fa95fa9f323]

[Oct 29 09:36:15] ERROR[2134][C-00000012]: stasis_channels.c:1161 ast_channel_publish_varset: Error creating message
    -- Executing [s at root:42] Set("Local/s at root-00000011;2", "feature=1") in new stack
    -- Executing [s at root:43] Verbose("Local/s at root-00000011;2", "1,feature is 1 unfilteredfeat is ▒=") in new stack
 feature is 1 unfilteredfeat is ▒=
```


> FILE function grabs garbage along with read data when target line has no newline
> --------------------------------------------------------------------------------
>
>                 Key: ASTERISK-26481
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-26481
>             Project: Asterisk
>          Issue Type: Bug
>      Security Level: None
>          Components: Functions/General
>    Affects Versions: 14.0.1, 14.1.0
>         Environment: Linux 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:42:33 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
>            Reporter: Jonathan Harris
>              Labels: dialplan, file, len, string, variables
>         Attachments: ASTERISK-26481_workaround_fixes_only_half_the_code.patch, filereader_code.txt, filereader_output.txt
>
>
> *Edited by Rusty Newton*
> The description and comments were a little confusing. Here is working dialplan to reproduce the issue:
> {noformat}
> exten => 5,1,Verbose(Context: ${CONTEXT} Exten:${EXTEN})
>     same => n,Set(featurefile=/etc/asterisk/testfile.txt)
>     same => n,Set(myList=A,AB,ABC,ABCD,ABCDE,ABCDEF,ABCDEFG,ABCDEFGH)
>     same => n,While($["${SET(rawVar=${SHIFT(myList)})}" != ""])
>     same => n,Verbose(rawVar is set to ${rawVar})
>     same => n,Set(FILE(${featurefile})=${rawVar})
>     same => n,Set(fileVar=${FILE(${featurefile},0,1,l,u)})
>     same => n,Set(hexDump=${SHELL(hd ${featurefile})})
>     same => n,Verbose(Before file: ---${rawVar}--- len ${LEN(${rawVar})} after file: ---${fileVar}--- LEN ${LEN(${fileVar})} hexdump:${hexDump})
>     same => n,EndWhile()
>     same => n,Hangup()
> {noformat}
> When FILE reads the file with more than one character it grabs garbage.
> {noformat}
> newtonr-laptop*CLI> channel originate LOCAL/5 at from-internal application wait 600
>     -- Called 5 at from-internal
>     -- Executing [5 at from-internal:1] Verbose("Local/5 at from-internal-00000018;2", "Context: from-internal Exten:5") in new stack
> Context: from-internal Exten:5
>     -- Executing [5 at from-internal:2] Set("Local/5 at from-internal-00000018;2", "featurefile=/etc/asterisk/testfile.txt") in new stack
>     -- Executing [5 at from-internal:3] Set("Local/5 at from-internal-00000018;2", "myList=A,AB,ABC,ABCD,ABCDE,ABCDEF,ABCDEFG,ABCDEFGH") in new stack
>     -- Executing [5 at from-internal:4] While("Local/5 at from-internal-00000018;2", "1") in new stack
>     -- Executing [5 at from-internal:5] Verbose("Local/5 at from-internal-00000018;2", "rawVar is set to A") in new stack
> rawVar is set to A
>     -- Executing [5 at from-internal:6] Set("Local/5 at from-internal-00000018;2", "FILE(/etc/asterisk/testfile.txt)=A") in new stack
>     -- Executing [5 at from-internal:7] Set("Local/5 at from-internal-00000018;2", "fileVar=A") in new stack
>     -- Executing [5 at from-internal:8] Set("Local/5 at from-internal-00000018;2", "hexDump=00000000  41                                                |A|
>     -- 00000001
>     -- ") in new stack
>     -- Executing [5 at from-internal:9] Verbose("Local/5 at from-internal-00000018;2", "Before file: ---A--- len 1 after file: ---A--- LEN 1 hexdump:00000000  41                                                |A|
>     -- 00000001
>     -- ") in new stack
> Before file: ---A--- len 1 after file: ---A--- LEN 1 hexdump:00000000  41                                                |A|
> 00000001
>     -- Executing [5 at from-internal:10] EndWhile("Local/5 at from-internal-00000018;2", "") in new stack
>     -- Executing [5 at from-internal:4] While("Local/5 at from-internal-00000018;2", "1") in new stack
>     -- Executing [5 at from-internal:5] Verbose("Local/5 at from-internal-00000018;2", "rawVar is set to AB") in new stack
> rawVar is set to AB
>     -- Executing [5 at from-internal:6] Set("Local/5 at from-internal-00000018;2", "FILE(/etc/asterisk/testfile.txt)=AB") in new stack
>     -- Executing [5 at from-internal:7] Set("Local/5 at from-internal-00000018;2", "fileVar=ABU��") in new stack
> [Oct 27 17:18:45] ERROR[12266][C-00000019]: json.c:825 ast_json_vpack: Error building JSON from '{s: s, s: s}': Invalid UTF-8 string.
> [Oct 27 17:18:45] ERROR[12266][C-00000019]: stasis_channels.c:773 ast_channel_publish_varset: Error creating message
>     -- Executing [5 at from-internal:8] Set("Local/5 at from-internal-00000018;2", "hexDump=00000000  41 42                                             |AB|
>     -- 00000002
>     -- ") in new stack
>     -- Executing [5 at from-internal:9] Verbose("Local/5 at from-internal-00000018;2", "Before file: ---AB--- len 2 after file: ---ABU��--- LEN 6 hexdump:00000000  41 42                                             |AB|
>     -- 00000002
>     -- ") in new stack
> Before file: ---AB--- len 2 after file: ---ABU��--- LEN 6 hexdump:00000000  41 42                                             |AB|
> 00000002
>     -- Executing [5 at from-internal:10] EndWhile("Local/5 at from-internal-00000018;2", "") in new stack
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list