Print this page
10110 get_tz_countries shouldn't check array for NULL


   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"


  28 
  29 #include <stdlib.h>
  30 #include <stdio.h>
  31 #include <string.h>
  32 #include <unistd.h>
  33 #include <sys/param.h>
  34 #include <sys/types.h>
  35 #include <sys/stat.h>
  36 #include <tzfile.h>
  37 #include <fcntl.h>
  38 #include <regex.h>
  39 #include <errno.h>
  40 #include <libintl.h>
  41 #include <libzoneinfo.h>
  42 
  43 #define DEFINIT         "/etc/default/init"
  44 #define ZONEINFOTABDIR  "/usr/share/lib/zoneinfo/tab/"
  45 #define CONTINENT_TAB   ZONEINFOTABDIR "continent.tab"
  46 #define COUNTRY_TAB     ZONEINFOTABDIR "country.tab"
  47 #define ZONE_SUN_TAB    ZONEINFOTABDIR "zone_sun.tab"


 194 }
 195 
 196 /*
 197  * get_tz_countries() finds the list of countries from the zone_sun.tab
 198  * file, for the input continent, and retrieves the country
 199  * names from the country.tab file.  It also retrieves the localized
 200  * country names.  The returned list of countries is sorted by the
 201  * countries' localized name fields.
 202  */
 203 int
 204 get_tz_countries(struct tz_country **country, struct tz_continent *cont)
 205 {
 206         FILE *fp_zone, *fp_cc;
 207         char buff[BUFFLEN], ccbuf[_CCBUFLEN], *ptr;
 208         char *lp, *lptr, *lp_coord, *lp_cc, *lp_tz;     /* line pointer */
 209         struct tz_country *head = NULL, *prev = NULL, *next, *cp, *cp2;
 210         int sav_errno = 0, ncount, i;
 211         int cmp, status;
 212         size_t len, len_coord, len_ctnt;
 213 
 214         if (cont->ctnt_name == NULL) {
 215                 errno = EINVAL;
 216                 return (-1);
 217         }
 218         len_ctnt = strlen(cont->ctnt_name);
 219         ccbuf[0] = '\0';
 220 
 221         /* open zone_sun.tab and country.tab files */
 222         if ((fp_zone = fopen(ZONE_SUN_TAB, "r")) == NULL) {
 223                 /* fopen() sets errno */
 224                 return (-1);
 225         }
 226         if ((fp_cc = fopen(COUNTRY_TAB, "r")) == NULL) {
 227                 /* fopen() sets errno */
 228                 (void) fclose(fp_zone);
 229                 return (-1);
 230         }
 231 
 232         /* read timezones to match continents, and get countries */
 233         ncount = 0;
 234         /*CONSTANTCONDITION*/
 235         while (1) {
 236                 if (fgets(buff, sizeof (buff), fp_zone) == NULL) {
 237                         if (feof(fp_zone) == 0) {




   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2018, Joyent, Inc.
  29  */
  30 
  31 #include <stdlib.h>
  32 #include <stdio.h>
  33 #include <string.h>
  34 #include <unistd.h>
  35 #include <sys/param.h>
  36 #include <sys/types.h>
  37 #include <sys/stat.h>
  38 #include <tzfile.h>
  39 #include <fcntl.h>
  40 #include <regex.h>
  41 #include <errno.h>
  42 #include <libintl.h>
  43 #include <libzoneinfo.h>
  44 
  45 #define DEFINIT         "/etc/default/init"
  46 #define ZONEINFOTABDIR  "/usr/share/lib/zoneinfo/tab/"
  47 #define CONTINENT_TAB   ZONEINFOTABDIR "continent.tab"
  48 #define COUNTRY_TAB     ZONEINFOTABDIR "country.tab"
  49 #define ZONE_SUN_TAB    ZONEINFOTABDIR "zone_sun.tab"


 196 }
 197 
 198 /*
 199  * get_tz_countries() finds the list of countries from the zone_sun.tab
 200  * file, for the input continent, and retrieves the country
 201  * names from the country.tab file.  It also retrieves the localized
 202  * country names.  The returned list of countries is sorted by the
 203  * countries' localized name fields.
 204  */
 205 int
 206 get_tz_countries(struct tz_country **country, struct tz_continent *cont)
 207 {
 208         FILE *fp_zone, *fp_cc;
 209         char buff[BUFFLEN], ccbuf[_CCBUFLEN], *ptr;
 210         char *lp, *lptr, *lp_coord, *lp_cc, *lp_tz;     /* line pointer */
 211         struct tz_country *head = NULL, *prev = NULL, *next, *cp, *cp2;
 212         int sav_errno = 0, ncount, i;
 213         int cmp, status;
 214         size_t len, len_coord, len_ctnt;
 215 




 216         len_ctnt = strlen(cont->ctnt_name);
 217         ccbuf[0] = '\0';
 218 
 219         /* open zone_sun.tab and country.tab files */
 220         if ((fp_zone = fopen(ZONE_SUN_TAB, "r")) == NULL) {
 221                 /* fopen() sets errno */
 222                 return (-1);
 223         }
 224         if ((fp_cc = fopen(COUNTRY_TAB, "r")) == NULL) {
 225                 /* fopen() sets errno */
 226                 (void) fclose(fp_zone);
 227                 return (-1);
 228         }
 229 
 230         /* read timezones to match continents, and get countries */
 231         ncount = 0;
 232         /*CONSTANTCONDITION*/
 233         while (1) {
 234                 if (fgets(buff, sizeof (buff), fp_zone) == NULL) {
 235                         if (feof(fp_zone) == 0) {