Print this page
11927 Log, or optionally panic, on zero-length kmem allocations
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>

@@ -21,10 +21,11 @@
 
 /*
  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2015 Joyent, Inc.  All rights reserved.
  */
 
 #include <sys/param.h>
 #include <sys/errno.h>
 #include <sys/vfs.h>

@@ -559,15 +560,20 @@
         switch (res.stat) {
                 case NFSAUTH_DR_OKAY:
                         *access = res.ares.auth_perm;
                         *srv_uid = res.ares.auth_srv_uid;
                         *srv_gid = res.ares.auth_srv_gid;
-                        *srv_gids_cnt = res.ares.auth_srv_gids.len;
-                        *srv_gids = kmem_alloc(*srv_gids_cnt * sizeof (gid_t),
-                            KM_SLEEP);
+
+                        if ((*srv_gids_cnt = res.ares.auth_srv_gids.len) != 0) {
+                                *srv_gids = kmem_alloc(*srv_gids_cnt *
+                                    sizeof (gid_t), KM_SLEEP);
                         bcopy(res.ares.auth_srv_gids.val, *srv_gids,
                             *srv_gids_cnt * sizeof (gid_t));
+                        } else {
+                                *srv_gids = NULL;
+                        }
+
                         break;
 
                 case NFSAUTH_DR_EFAIL:
                 case NFSAUTH_DR_DECERR:
                 case NFSAUTH_DR_BADCMD:

@@ -1052,14 +1058,18 @@
                 if (uid != NULL)
                         *uid = p->auth_srv_uid;
                 if (gid != NULL)
                         *gid = p->auth_srv_gid;
                 if (ngids != NULL && gids != NULL) {
-                        *ngids = p->auth_srv_ngids;
-                        *gids = kmem_alloc(*ngids * sizeof (gid_t), KM_SLEEP);
-                        bcopy(p->auth_srv_gids, *gids, *ngids * sizeof (gid_t));
+                        if ((*ngids = p->auth_srv_ngids) != 0) {
+                                size_t sz = *ngids * sizeof (gid_t);
+                                *gids = kmem_alloc(sz, KM_SLEEP);
+                                bcopy(p->auth_srv_gids, *gids, sz);
+                        } else {
+                                *gids = NULL;
                 }
+                }
 
                 access = p->auth_access;
 
                 if ((refresh > NFSAUTH_CACHE_REFRESH) &&
                     p->auth_state == NFS_AUTH_FRESH) {