Просмотр исходного кода

Consistently use empty list instead of nil/null when logging/transporting authorization info

Rod Hynes 8 лет назад
Родитель
Сommit
5be654c7d9
2 измененных файлов с 11 добавлено и 2 удалено
  1. 6 0
      psiphon/notice.go
  2. 5 2
      psiphon/server/tunnelServer.go

+ 6 - 0
psiphon/notice.go

@@ -714,6 +714,12 @@ func NoticeServerTimestamp(timestamp string) {
 // NoticeActiveAuthorizationIDs reports the authorizations the server has accepted.
 // Each ID is a base64-encoded accesscontrol.Authorization.ID value.
 func NoticeActiveAuthorizationIDs(activeAuthorizationIDs []string) {
+
+	// Never emit 'null' instead of empty list
+	if activeAuthorizationIDs == nil {
+		activeAuthorizationIDs = make([]string, 0)
+	}
+
 	singletonNoticeLogger.outputNotice(
 		"ActiveAuthorizationIDs", 0,
 		"IDs", activeAuthorizationIDs)

+ 5 - 2
psiphon/server/tunnelServer.go

@@ -1791,8 +1791,11 @@ func (sshClient *sshClient) setHandshakeState(
 	// and is used to detect and prevent multiple malicious clients from reusing a
 	// single authorization (within the scope of this server).
 
-	var authorizationIDs []string
-	var authorizedAccessTypes []string
+	// authorizationIDs and authorizedAccessTypes are returned to the client and logged,
+	// respectively; initialize to empty lists so the protocol/logs don't need to handle
+	// 'null' values.
+	authorizationIDs = make([]string, 0)
+	authorizedAccessTypes = make([]string, 0)
 	var stopTime time.Time
 
 	for i, authorization := range authorizations {