Print this page
10128 csplit should use strlcpy

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/csplit/csplit.c
          +++ new/usr/src/cmd/csplit/csplit.c
↓ open down ↓ 19 lines elided ↑ open up ↑
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   */
  25   25  
  26   26  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  27   27  /*        All Rights Reserved   */
  28   28  
  29   29  /*
       30 + * Copyright (c) 2018, Joyent, Inc.
       31 + */
       32 +
       33 +/*
  30   34   * csplit - Context or line file splitter
  31   35   * Compile: cc -O -s -o csplit csplit.c
  32   36   */
  33   37  
  34   38  #include <stdio.h>
  35   39  #include <stdlib.h>
  36   40  #include <unistd.h>
  37   41  #include <string.h>
  38   42  #include <ctype.h>
  39   43  #include <errno.h>
↓ open down ↓ 344 lines elided ↑ open up ↑
 384  388                           * ..... ^ file
 385  389                           * ............. ^ delim
 386  390                           */
 387  391                          if (strlen(delim + 1) > pathconf(file, _PC_NAME_MAX)) {
 388  392                                  fatal("Name too long: %s\n", delim + 1);
 389  393                          }
 390  394                          *delim = savedelim;
 391  395                  }
 392  396  
 393  397                  if ((opfil = fopen(file, "w")) == NULL) {
 394      -                        (void) strcpy(tfile, file);
      398 +                        (void) strlcpy(tfile, file, sizeof (tfile));
 395  399                          (void) sprintf(fptr, "%.*d", fiwidth, (ctr-2));
 396  400                          fatal("Cannot create %s\n", tfile);
 397  401                  }
 398  402                  return (opfil);
 399  403          }
 400  404          return (NULL);
 401  405  }
 402  406  
 403  407  /*
 404  408   * Getline gets a line via fgets from the input stream "infile".
↓ open down ↓ 190 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX