tindy2013 / subconverter

Utility to convert between various subscription format
GNU General Public License v3.0
13.18k stars 2.82k forks source link

[BUG] Segmentation fault 但是文件权限问题 #617

Open wsm25 opened 1 year ago

wsm25 commented 1 year ago

确认版本最新

检索issue

subconverter版本

v0.7.2

转换过程

clash 转 clash

转换设置

sub?target=clash&url=xxx&config=https%3A%2F%2Fraw.githubusercontent.com%2FCareyWang%2FRules%2Fmaster%2FRemoteConfig%2Funiversal%2Fno-urltest.ini&emoji=true&list=false&udp=false&tfo=false&scv=false&fdn=false&sort=false

复现步骤

为了配置一个 service,将文件夹移至 /usr/share 下,运行 /usr/share/subconverter/subconverter,访问 subconverter 地址立即报错 Segmentation fault

期望结果

正常输出

实际结果

Segmentation fault

错误信息

...
2023/06/27 Tue 12:32:52.298320 [44563 139938456647424][VERB] CACHE MISS: 'https://raw.githubusercontent.com/CareyWang/Rules/master/RemoteConfig/universal/no-urltest.ini', TTL timeout, creating new cache.
*   Trying [2606:50c0:8000::154]:443...
*   Trying 185.199.108.133:443...
* Connected to raw.githubusercontent.com (185.199.108.133) port 443 (#0)
* mbedTLS: Connecting to raw.githubusercontent.com:443
* mbedTLS: Set min SSL version to TLS 1.0
* mbedTLS: Handshake complete, cipher is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256
* Dumping cert info: * cert. version     : 3
* serial number     : 04:4D:72:D7:7C:DD:A7:02:DD:5A:67:F2:A2:3B:BD:D9
* issuer name       : C=US, O=DigiCert Inc, CN=DigiCert TLS RSA SHA256 2020 CA1
* subject name      : C=US, ST=California, L=San Francisco, O=GitHub, Inc., CN=*.github.io
* issued  on        : 2023-02-21 00:00:00
* expires on        : 2024-03-20 23:59:59
* signed using      : RSA with SHA-256
* RSA key size      : 2048 bits
* basic constraints : CA=false
* subject alt name  : *.github.io, github.io, *.github.com, github.com, www.github.com, *.githubusercontent.com, githubusercontent.com
* key usage         : Digital Signature, Key Encipherment
* ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication

* SSL connected
* using HTTP/1.x
> GET /CareyWang/Rules/master/RemoteConfig/universal/no-urltest.ini HTTP/1.1
Host: raw.githubusercontent.com
User-Agent: subconverter/v0.7.2 cURL/7.88.1-DEV
Accept: */*
Content-Type: application/json;charset=utf-8
SubConverter-Request: 1
SubConverter-Version: v0.7.2

< HTTP/1.1 200 OK
< Connection: keep-alive
< Content-Length: 2219
< Cache-Control: max-age=300
< Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
< Content-Type: text/plain; charset=utf-8
< ETag: "7d4d2c4851ac4b5fe9fa3c7fbeb3c433bc15af989e95d06b60b436b628626492"
< Strict-Transport-Security: max-age=31536000
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-XSS-Protection: 1; mode=block
< X-GitHub-Request-Id: 7634:9489:52FD6:6249F:649B04CA
< Accept-Ranges: bytes
< Date: Tue, 27 Jun 2023 16:32:52 GMT
< Via: 1.1 varnish
< X-Served-By: cache-sna10731-LGB
< X-Cache: HIT
< X-Cache-Hits: 1
< X-Timer: S1687883573.547666,VS0,VE281
< Vary: Authorization,Accept-Encoding,Origin
< Access-Control-Allow-Origin: *
< Cross-Origin-Resource-Policy: cross-origin
< X-Fastly-Request-ID: 8d3e2d36833b576a78e04cdc0d5e9c17e530c23d
< Expires: Tue, 27 Jun 2023 16:37:52 GMT
< Source-Age: 0
<
* Connection #0 to host raw.githubusercontent.com left intact
Segmentation fault
wsm25 commented 1 year ago

用 root 运行就没有问题。基于上述输出猜测是把 Cache 写入磁盘的时候的问题。 gdb 输出:

Thread 26 "subconverter" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff482e700 (LWP 44631)]
0x00007ffff78e9161 in __GI__IO_fwrite (buf=0x7fffe801d530, size=1, count=2219, fp=0x0) at iofwrite.c:37
37      iofwrite.c: No such file or directory.

可以看到这里的 fp 是 0,可能是没有检查文件是否可写入就直接写入。

wsm25 commented 1 year ago

调用栈:

#0  0x00007ffff78e9161 in __GI__IO_fwrite (buf=0x7fffe801d530, size=1, count=2219, fp=0x0) at iofwrite.c:37
#1  0x000055555576baea in fileWrite (path="cache/4074ea87243959c457d3eb895b417b72",
    content=";设置规则标志位\nsurge_ruleset=REJECT,rules/DivineEngine/Surge/Ruleset/Guard/Hijacking.list\nsurge_ruleset=DIRECT,https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RuleSet/ForceDirect"..., overwrite=true)
    at /src/utils/file.cpp:107
#2  0x000055555567f6ee in webGet (
    url="https://raw.githubusercontent.com/CareyWang/Rules/master/RemoteConfig/universal/no-urltest.ini", proxy="",
    cache_ttl=300, response_headers=0x0, request_headers=0x0) at /src/handler/webget.cpp:359
#3  0x00005555556708ef in operator() (__closure=0x7ffff002e7f8) at /src/handler/multithread.cpp:69
...