Print this page
5679 be_sort_list(): Possible null pointer dereference


   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  28  * Copyright 2015 Toomas Soome <tsoome@me.com>

  29  */
  30 
  31 /*
  32  * System includes
  33  */
  34 
  35 #include <assert.h>
  36 #include <stdio.h>
  37 #include <strings.h>
  38 #include <libzfs.h>
  39 #include <locale.h>
  40 #include <langinfo.h>
  41 #include <stdlib.h>
  42 #include <wchar.h>
  43 #include <sys/types.h>
  44 
  45 #include "libbe.h"
  46 
  47 #ifndef lint
  48 #define _(x) gettext(x)


1161 
1162                 dsets = B_TRUE;
1163                 snaps = B_TRUE;
1164         }
1165 
1166         argc -= optind;
1167         argv += optind;
1168 
1169 
1170         if (argc == 1)
1171                 be_name = argv[0];
1172 
1173         err = be_list(be_name, &be_nodes);
1174 
1175         switch (err) {
1176         case BE_SUCCESS:
1177                 /* the default sort is ascending date, no need to sort twice */
1178                 if (order == BE_SORT_UNSPECIFIED)
1179                         order = BE_SORT_DATE;
1180 
1181                 if (order != BE_SORT_DATE)
1182                         be_sort(&be_nodes, order);








1183 
1184                 print_nodes(be_name, dsets, snaps, parsable, be_nodes);
1185                 break;
1186         case BE_ERR_BE_NOENT:
1187                 if (be_name == NULL)
1188                         (void) fprintf(stderr, _("No boot environments found "
1189                             "on this system.\n"));
1190                 else {
1191                         (void) fprintf(stderr, _("%s does not exist or appear "
1192                             "to be a valid BE.\nPlease check that the name of "
1193                             "the BE provided is correct.\n"), be_name);
1194                 }
1195                 break;
1196         default:
1197                 (void) fprintf(stderr, _("Unable to display Boot "
1198                     "Environment\n"));
1199                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1200         }
1201 
1202         if (be_nodes != NULL)




   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  28  * Copyright 2015 Toomas Soome <tsoome@me.com>
  29  * Copyright 2015 Gary Mills
  30  */
  31 
  32 /*
  33  * System includes
  34  */
  35 
  36 #include <assert.h>
  37 #include <stdio.h>
  38 #include <strings.h>
  39 #include <libzfs.h>
  40 #include <locale.h>
  41 #include <langinfo.h>
  42 #include <stdlib.h>
  43 #include <wchar.h>
  44 #include <sys/types.h>
  45 
  46 #include "libbe.h"
  47 
  48 #ifndef lint
  49 #define _(x) gettext(x)


1162 
1163                 dsets = B_TRUE;
1164                 snaps = B_TRUE;
1165         }
1166 
1167         argc -= optind;
1168         argv += optind;
1169 
1170 
1171         if (argc == 1)
1172                 be_name = argv[0];
1173 
1174         err = be_list(be_name, &be_nodes);
1175 
1176         switch (err) {
1177         case BE_SUCCESS:
1178                 /* the default sort is ascending date, no need to sort twice */
1179                 if (order == BE_SORT_UNSPECIFIED)
1180                         order = BE_SORT_DATE;
1181 
1182                 if (order != BE_SORT_DATE) {
1183                         err = be_sort(&be_nodes, order);
1184                         if (err != BE_SUCCESS) {
1185                                 (void) fprintf(stderr, _("Unable to sort Boot "
1186                                     "Environment\n"));
1187                                 (void) fprintf(stderr, "%s\n",
1188                                     be_err_to_str(err));
1189                                 break;
1190                         }
1191                 }
1192 
1193                 print_nodes(be_name, dsets, snaps, parsable, be_nodes);
1194                 break;
1195         case BE_ERR_BE_NOENT:
1196                 if (be_name == NULL)
1197                         (void) fprintf(stderr, _("No boot environments found "
1198                             "on this system.\n"));
1199                 else {
1200                         (void) fprintf(stderr, _("%s does not exist or appear "
1201                             "to be a valid BE.\nPlease check that the name of "
1202                             "the BE provided is correct.\n"), be_name);
1203                 }
1204                 break;
1205         default:
1206                 (void) fprintf(stderr, _("Unable to display Boot "
1207                     "Environment\n"));
1208                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1209         }
1210 
1211         if (be_nodes != NULL)