Print this page
10088 ldterm_do_ioctl() shouldn't check for a NULL array


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
  25  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
  26  */
  27 
  28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T  */
  29 /* All Rights Reserved                                  */
  30 
  31 /*
  32  * University Copyright- Copyright (c) 1982, 1986, 1988
  33  * The Regents of the University of California
  34  * All Rights Reserved
  35  *
  36  * University Acknowledgment- Portions of this document are derived from
  37  * software developed by the University of California, Berkeley, and its
  38  * contributors.
  39  */
  40 
  41 /*
  42  * Standard Streams Terminal Line Discipline module.
  43  */
  44 


4582                                 if (csdp->eucpc_data[i].byte_length >
4583                                     LDTERM_CS_MAX_BYTE_LENGTH) {
4584                                         miocnak(q, mp, 0, ERANGE);
4585                                         return;
4586                                 }
4587                                 if (csdp->eucpc_data[i].byte_length >
4588                                     maxbytelen)
4589                                         maxbytelen =
4590                                             csdp->eucpc_data[i].byte_length;
4591                                 if (csdp->eucpc_data[i].screen_width >
4592                                     maxscreenlen)
4593                                         maxscreenlen =
4594                                             csdp->eucpc_data[i].screen_width;
4595                         }
4596                 } else if (csdp->codeset_type == LDTERM_CS_TYPE_UTF8) {
4597                         maxbytelen = 4;
4598                         maxscreenlen = 2;
4599                 }
4600 
4601                 locale_name_sz = 0;
4602                 if (csdp->locale_name) {
4603                         for (i = 0; i < MAXNAMELEN; i++)
4604                                 if (csdp->locale_name[i] == '\0')
4605                                         break;
4606                         /*
4607                          * We cannot have any string that is not NULL byte
4608                          * terminated.
4609                          */
4610                         if (i >= MAXNAMELEN) {
4611                                 miocnak(q, mp, 0, ERANGE);
4612                                 return;
4613                         }
4614 
4615                         locale_name_sz = i + 1;
4616                 }
4617 
4618                 /*
4619                  * As the final check, if there was invalid codeset_type
4620                  * given, or invalid byte_length was specified, it's an error.
4621                  */
4622                 if (maxbytelen <= 0 || maxscreenlen <= 0) {
4623                         miocnak(q, mp, 0, ERANGE);
4624                         return;
4625                 }
4626 
4627                 /* Do the switching. */
4628                 tp->t_maxeuc = maxbytelen;
4629                 tp->t_state &= ~TS_MEUC;
4630                 if (maxbytelen > 1 || maxscreenlen > 1) {
4631                         if (!tp->t_eucp_mp) {
4632                                 if (!(tp->t_eucp_mp = allocb(_TTY_BUFSIZ,
4633                                     BPRI_HI))) {
4634                                         cmn_err(CE_WARN,
4635                                             "Can't allocate eucp_mp");
4636                                         miocnak(q, mp, 0, ENOSR);




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright (c) 2018, Joyent, Inc.
  25  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
  26  */
  27 
  28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T  */
  29 /* All Rights Reserved                                  */
  30 
  31 /*
  32  * University Copyright- Copyright (c) 1982, 1986, 1988
  33  * The Regents of the University of California
  34  * All Rights Reserved
  35  *
  36  * University Acknowledgment- Portions of this document are derived from
  37  * software developed by the University of California, Berkeley, and its
  38  * contributors.
  39  */
  40 
  41 /*
  42  * Standard Streams Terminal Line Discipline module.
  43  */
  44 


4582                                 if (csdp->eucpc_data[i].byte_length >
4583                                     LDTERM_CS_MAX_BYTE_LENGTH) {
4584                                         miocnak(q, mp, 0, ERANGE);
4585                                         return;
4586                                 }
4587                                 if (csdp->eucpc_data[i].byte_length >
4588                                     maxbytelen)
4589                                         maxbytelen =
4590                                             csdp->eucpc_data[i].byte_length;
4591                                 if (csdp->eucpc_data[i].screen_width >
4592                                     maxscreenlen)
4593                                         maxscreenlen =
4594                                             csdp->eucpc_data[i].screen_width;
4595                         }
4596                 } else if (csdp->codeset_type == LDTERM_CS_TYPE_UTF8) {
4597                         maxbytelen = 4;
4598                         maxscreenlen = 2;
4599                 }
4600 
4601                 locale_name_sz = 0;
4602 
4603                 for (i = 0; i < MAXNAMELEN; i++)
4604                         if (csdp->locale_name[i] == '\0')
4605                                 break;
4606                 /*
4607                  * We cannot have any string that is not NULL byte
4608                  * terminated.
4609                  */
4610                 if (i >= MAXNAMELEN) {
4611                         miocnak(q, mp, 0, ERANGE);
4612                         return;
4613                 }
4614 
4615                 locale_name_sz = i + 1;

4616 
4617                 /*
4618                  * As the final check, if there was invalid codeset_type
4619                  * given, or invalid byte_length was specified, it's an error.
4620                  */
4621                 if (maxbytelen <= 0 || maxscreenlen <= 0) {
4622                         miocnak(q, mp, 0, ERANGE);
4623                         return;
4624                 }
4625 
4626                 /* Do the switching. */
4627                 tp->t_maxeuc = maxbytelen;
4628                 tp->t_state &= ~TS_MEUC;
4629                 if (maxbytelen > 1 || maxscreenlen > 1) {
4630                         if (!tp->t_eucp_mp) {
4631                                 if (!(tp->t_eucp_mp = allocb(_TTY_BUFSIZ,
4632                                     BPRI_HI))) {
4633                                         cmn_err(CE_WARN,
4634                                             "Can't allocate eucp_mp");
4635                                         miocnak(q, mp, 0, ENOSR);