Skip to content

Commit 65d7070

Browse files
authored
Merge pull request #78 from wiwi878/fix/udm/sdm-notify-204-nil-guard
fix: return 204 when UE context missing and avoid nil deref
2 parents 504b144 + a9971f3 commit 65d7070

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

internal/sbi/api_httpcallback.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/free5gc/openapi/models"
1010
"github.com/free5gc/udm/internal/logger"
1111
"github.com/free5gc/util/metrics/sbi"
12+
"github.com/free5gc/util/validator"
1213
)
1314

1415
func (s *Server) getHttpCallBackRoutes() []Route {
@@ -23,7 +24,7 @@ func (s *Server) getHttpCallBackRoutes() []Route {
2324
{
2425
"DataChangeNotificationToNF",
2526
http.MethodPost,
26-
"/sdm-subscriptions",
27+
"/:supi/sdm-subscriptions",
2728
s.HandleDataChangeNotificationToNF,
2829
},
2930
}
@@ -59,7 +60,33 @@ func (s *Server) HandleDataChangeNotificationToNF(c *gin.Context) {
5960
return
6061
}
6162

63+
// TS 29.503 6.1.6.2.21
64+
if len(dataChangeNotify.NotifyItems) == 0 {
65+
problemDetail := models.ProblemDetails{
66+
Title: "Missing or invalid parameter",
67+
Status: http.StatusBadRequest,
68+
Detail: "Mandatory IE NotifyItems is missing or invalid",
69+
Cause: "MANDATORY_IE_MISSING",
70+
}
71+
logger.CallbackLog.Warnln("Mandatory IE NotifyItems is missing or invalid")
72+
c.Set(sbi.IN_PB_DETAILS_CTX_STR, http.StatusText(int(problemDetail.Status)))
73+
c.JSON(int(problemDetail.Status), problemDetail)
74+
return
75+
}
76+
6277
supi := c.Params.ByName("supi")
78+
if !validator.IsValidSupi(supi) {
79+
problemDetail := models.ProblemDetails{
80+
Title: "Invalid Supi format",
81+
Status: http.StatusBadRequest,
82+
Detail: "The Supi format is invalid",
83+
Cause: "MANDATORY_IE_INCORRECT",
84+
}
85+
logger.UecmLog.Warnf("Registration Reject: Invalid Supi format [%s]", supi)
86+
c.Set(sbi.IN_PB_DETAILS_CTX_STR, http.StatusText(int(problemDetail.Status)))
87+
c.JSON(int(problemDetail.Status), problemDetail)
88+
return
89+
}
6390

6491
logger.CallbackLog.Infof("Handle DataChangeNotificationToNF")
6592

internal/sbi/processor/notifier.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package processor
22

33
import (
4+
"net/http"
5+
46
"github.com/gin-gonic/gin"
57

68
"github.com/free5gc/openapi"
@@ -22,7 +24,11 @@ func (p *Processor) DataChangeNotificationProcedure(c *gin.Context,
2224
return
2325
}
2426

25-
ue, _ := p.Context().UdmUeFindBySupi(supi)
27+
ue, ok := p.Context().UdmUeFindBySupi(supi)
28+
if !ok {
29+
c.Status(http.StatusNoContent)
30+
return
31+
}
2632

2733
clientAPI := p.Consumer().GetSDMClient("DataChangeNotification")
2834

@@ -48,6 +54,10 @@ func (p *Processor) DataChangeNotificationProcedure(c *gin.Context,
4854
}
4955
}
5056
}
57+
if problemDetails == nil {
58+
c.Status(http.StatusNoContent)
59+
return
60+
}
5161
c.Set(sbi.IN_PB_DETAILS_CTX_STR, problemDetails.Cause)
5262
c.JSON(int(problemDetails.Status), problemDetails)
5363
}

0 commit comments

Comments
 (0)