seslabSJU / tinyIoT

7 stars 0 forks source link

Adding a group as a member of another group makes server crash #18

Closed reinaortega closed 3 months ago

reinaortega commented 5 months ago

Adding a group as a member of another group makes server crash with

GRP member TinyIoT/MyAe1/MyGroupResource type is inconsistent Segmentation fault (core dumped)

For test: TC_CSE_GMG_CRE_007

LAMXkE commented 4 months ago

Seems it is fixed. Request with memberType 0 (Mixed)

POST /TinyIoT/EV1 HTTP/1.1
Accept: application/json
X-M2M-RI: 12345
X-M2M-Origin: COrigin
Content-Type: application/json;ty=9
User-Agent: PostmanRuntime/7.36.0
Postman-Token: 36b130af-c26f-46b1-9e5f-10089ff40f32
Host: 127.0.0.1:3000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 232

{
    "m2m:grp": {
        "rn": "cntGrp2",
        "mid": [
            "TinyIoT/EV1/data4",
            "TinyIoT/EV1/cntGrp"

        ],
        "mnm": 10,
        "mt":0,
        "csy": 1,
        "macp": ["TinyIoT/acp2"]
    }
}
HTTP/1.1 201 Created
Connection: Close
Accept: application/json
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Accept-Language, Content-Language, Content-Type, X-M2M-Origin, X-M2M-RI, X-M2M-RVI
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
Access-Control-Request-Methods: GET, PUT, POST, DELETE, OPTIONS
Content-Length: 264
X-M2M-RSC: 2001
X-M2M-RI: 12345

{"m2m:grp":{"rn":"cntGrp2","mnm":10,"mt":0,"csy":1,"macp":["TinyIoT/acp2"],"ty":9,"ct":"20240308T140526","ri":"9-20240308T1405260000","lt":"20240308T140526","pi":"COrigin","et":"20260308T140526","cnm":2,"mtv":true,"mid":["TinyIoT/EV1/data4","TinyIoT/EV1/cntGrp"]}}

Request with memberType 3 (Container)

POST /TinyIoT/EV1 HTTP/1.1
Accept: application/json
X-M2M-RI: 12345
X-M2M-Origin: COrigin
Content-Type: application/json;ty=9
User-Agent: PostmanRuntime/7.36.0
Postman-Token: 3a21b054-af1b-444c-9612-943c25b0ab8e
Host: 127.0.0.1:3000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 232

{
"m2m:grp": {
"rn": "cntGrp2",
"mid": [
"TinyIoT/EV1/data4",
"TinyIoT/EV1/cntGrp"
],
"mnm": 10,
"mt":3,
"csy": 1,
"macp": ["TinyIoT/acp2"]
}
}
HTTP/1.1 201 Created
Connection: Close
Accept: application/json
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Accept-Language, Content-Language, Content-Type, X-M2M-Origin, X-M2M-RI, X-M2M-RVI
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
Access-Control-Request-Methods: GET, PUT, POST, DELETE, OPTIONS
Content-Length: 243
X-M2M-RSC: 2001
X-M2M-RI: 12345

{"m2m:grp":{"rn":"cntGrp2","mnm":10,"mt":3,"csy":1,"macp":["TinyIoT/acp2"],"ty":9,"ct":"20240308T140645","ri":"9-20240308T1406450001","lt":"20240308T140645","pi":"COrigin","et":"20260308T140645","cnm":1,"mtv":true,"mid":["TinyIoT/EV1/data4"]}}
reinaortega commented 3 months ago

The error is still there. In the test case, there are two members, a group and a container (in this order), the group member is validated first, and as the type is inconsistent (mt=3), the validation stops and it returns a created group with zero members

LAMXkE commented 3 months ago

That's weird. I placed grp then cnt and set mt=3 and it still works fine. Same result on Linux 22.04 and MacOS14.

Mon Mar 11 22:20:54 2024 DEBUG [HTTP]: 

POST /TinyIoT/EV1 HTTP/1.1
Accept: application/json
X-M2M-RI: 12345
X-M2M-Origin: COrigin
Content-Type: application/json;ty=9
User-Agent: PostmanRuntime/7.36.0
Postman-Token: bd8738a3-4c7d-4444-9ae1-b4bc5bc7ca53
Host: 127.0.0.1:3000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 232

{
    "m2m:grp": {
        "rn": "cntGrp2",
        "mid": [
            "TinyIoT/EV1/cntGrp",
            "TinyIoT/EV1/data3"

        ],
        "mnm": 10,
        "mt":3,
        "csy": 1,
        "macp": ["TinyIoT/acp2"]
    }
}

Mon Mar 11 22:20:54 2024 DEBUG [HTTP]: [POST] /TinyIoT/EV1
Mon Mar 11 22:20:54 2024 DEBUG [HTTP]: fr: COrigin
Mon Mar 11 22:20:54 2024 DEBUG [HTTP]: to: TinyIoT/EV1
Mon Mar 11 22:20:54 2024 INFO  [HTTP]: Request : POST
Mon Mar 11 22:20:54 2024 INFO  [HTTP]: Client connected 127.0.0.1

Mon Mar 11 22:20:54 2024 DEBUG [HTTP]: ip: 127.0.0.1
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: CSE_RELATIVE
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: Hierarchical Addressing
Mon Mar 11 22:20:54 2024 DEBUG [MAIN]: handle_onem2m_request
Mon Mar 11 22:20:54 2024 INFO  [O2M]: Create GRP
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: Validating GRP
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: Hierarchical Addressing
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: acop-pv : 63, op : 1
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: Validating GRP member TinyIoT/EV1/cntGrp
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: CSE RELATIVE
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: Hierarchical Addressing
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: GRP member TinyIoT/EV1/cntGrp type is inconsistent
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: Validating GRP member TinyIoT/EV1/data3
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: CSE RELATIVE
Mon Mar 11 22:20:54 2024 DEBUG [UTIL]: Hierarchical Addressing
Mon Mar 11 22:20:54 2024 DEBUG [DB]: SQL: INSERT INTO grp (id, cr,mt,cnm,mnm,mid,macp,mtv,csy,gn) VALUES( (SELECT id FROM general WHERE ri=?),?,?,?,?,?,?,?,?,?);
Mon Mar 11 22:20:54 2024 DEBUG [O2M]: Add Resource Tree Node [Parent-ID] : COrigin, [Child-ID] : 9-20240311T2220540000
Mon Mar 11 22:20:54 2024 INFO  [UTIL]: Run time : 0.001427
Mon Mar 11 22:20:54 2024 DEBUG [HTTP]: 

HTTP/1.1 201 Created
Connection: Close
Accept: application/json
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Accept-Language, Content-Language, Content-Type, X-M2M-Origin, X-M2M-RI, X-M2M-RVI
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
Access-Control-Request-Methods: GET, PUT, POST, DELETE, OPTIONS
Content-Length: 243
X-M2M-RSC: 2001
X-M2M-RI: 12345

{"m2m:grp":{"rn":"cntGrp2","mnm":10,"mt":3,"csy":1,"macp":["TinyIoT/acp2"],"ty":9,"ct":"20240311T222054","ri":"9-20240311T2220540000","lt":"20240311T222054","pi":"COrigin","et":"20260311T222054","cnm":2,"mtv":true,"mid":["TinyIoT/EV1/data3"]}}

But it seems cnm is not updated properly so I fixed that part

reinaortega commented 3 months ago

You are using consistencyStrategy = 1, I am using consistencyStrategy = 2 (abandon group), so expected response is RSC=4110

LAMXkE commented 3 months ago

Fixed to return 4110 Member Type Inconsistent when Consistency Strategy = 2(Abandon group) 3f177408ba7955a7272bc67fbf327cfb0c63259b

SCR-20240312-buiw

What if csy = 2 and resource does not exists? Should I still return 4110 (Member Type Inconsistent)? TS 0004 7.4.13.2.1 says if validation fails and csy is 2 (Abandon Group) it should return 4110 It is a bit awkward for me that cse return 4110 when there is no actual member resource.

reinaortega commented 3 months ago

I confirm the fix now.

Regarding your question, you got a good point. I think the best would be that you create an issue at https://git.onem2m.org/issues/issues