Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: tokenserver/appengine/impl/machinetoken/rpc_mint_machine_token.go

Issue 2943403003: token-server: Fix panic when generating machine token for unrecognized machine. (Closed)
Patch Set: flatten Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tokenserver/appengine/impl/machinetoken/rpc_mint_machine_token.go
diff --git a/tokenserver/appengine/impl/machinetoken/rpc_mint_machine_token.go b/tokenserver/appengine/impl/machinetoken/rpc_mint_machine_token.go
index a4b20b52cf3d228d73e5870e83b2a2443245c121..cf873bc12b57d337c7669626a93a944268cadfe3 100644
--- a/tokenserver/appengine/impl/machinetoken/rpc_mint_machine_token.go
+++ b/tokenserver/appengine/impl/machinetoken/rpc_mint_machine_token.go
@@ -140,8 +140,19 @@ func (r *MintMachineTokenRPC) MintMachineToken(c context.Context, req *minter.Mi
switch tokenReq.TokenType {
case tokenserver.MachineTokenType_LUCI_MACHINE_TOKEN:
resp, body, err := r.mintLuciMachineToken(c, args)
- if err != nil {
+ switch {
+ case err != nil: // grpc-level error
return nil, err
+ case resp == nil: // should not happen
+ panic("both resp and err can't be nil")
+ case resp.ErrorCode != 0: // logic-level error
Vadim Sh. 2017/06/20 03:49:50 this is the actual fix: don't try to log the token
+ if resp.TokenResponse != nil {
+ panic("TokenResponse must be nil if ErrorCode != 0")
+ }
+ return resp, nil
+ }
+ if resp.TokenResponse == nil {
+ panic("TokenResponse must not be nil if ErrorCode == 0")
}
if r.LogToken != nil {
// Errors during logging are considered not fatal. bqlog library has

Powered by Google App Engine
This is Rietveld 408576698