Another nice cleanup from Larry. This adds a new last_char_is() function and
uses it to avoid possible buffer underruns whn strlen is zero, and avoid the possible space-hogging inline of strlen() in several cases. -Erik
This commit is contained in:
parent
3c3277f0bd
commit
c1bdffe99b
2
Makefile
2
Makefile
@ -248,7 +248,7 @@ process_escape_sequence.c read_package_field.c read_text_file_to_buffer.c \
|
||||
recursive_action.c safe_read.c safe_strncpy.c seek_ared_file.c syscalls.c \
|
||||
syslog_msg_with_name.c time_string.c trim.c untar.c unzip.c vdprintf.c \
|
||||
verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xregcomp.c interface.c \
|
||||
remove_file.c
|
||||
remove_file.c last_char_is.c
|
||||
LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
|
||||
LIBBB_CFLAGS = -I$(LIBBB)
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
|
@ -583,7 +583,7 @@ static int status_merge(void *status, package_t *pkgs)
|
||||
*/
|
||||
if ((fin = fopen(statusfile, "r")) != NULL) {
|
||||
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
|
||||
line[strlen(line) - 1] = '\0'; /* trim newline */
|
||||
chomp(line); /* trim newline */
|
||||
/* If we see a package header, find out if it's a package
|
||||
* that we have processed. if so, we skip that block for
|
||||
* now (write it at the end).
|
||||
|
@ -706,7 +706,7 @@ static int readTarFile(int tarFd, int extractFlag, int listFlag,
|
||||
case REGTYPE0:
|
||||
/* If the name ends in a '/' then assume it is
|
||||
* supposed to be a directory, and fall through */
|
||||
if (header.name[strlen(header.name)-1] != '/') {
|
||||
if (last_char_is(header.name,'/')) {
|
||||
if (tarExtractRegularFile(&header, extractFlag, tostdoutFlag)==FALSE)
|
||||
errorFlag=TRUE;
|
||||
break;
|
||||
|
@ -75,7 +75,7 @@ static void decompose_list(const char *list)
|
||||
/* handle multi-value cases */
|
||||
else if (nminus == 1) {
|
||||
/* handle 'N-' case */
|
||||
if (list[strlen(list) - 1] == '-') {
|
||||
if (last_char_is(list,'-')) {
|
||||
startpos = strtol(list, &ptr, 10);
|
||||
}
|
||||
/* handle '-M' case */
|
||||
|
2
cut.c
2
cut.c
@ -75,7 +75,7 @@ static void decompose_list(const char *list)
|
||||
/* handle multi-value cases */
|
||||
else if (nminus == 1) {
|
||||
/* handle 'N-' case */
|
||||
if (list[strlen(list) - 1] == '-') {
|
||||
if (last_char_is(list,'-')) {
|
||||
startpos = strtol(list, &ptr, 10);
|
||||
}
|
||||
/* handle '-M' case */
|
||||
|
2
dpkg.c
2
dpkg.c
@ -583,7 +583,7 @@ static int status_merge(void *status, package_t *pkgs)
|
||||
*/
|
||||
if ((fin = fopen(statusfile, "r")) != NULL) {
|
||||
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
|
||||
line[strlen(line) - 1] = '\0'; /* trim newline */
|
||||
chomp(line); /* trim newline */
|
||||
/* If we see a package header, find out if it's a package
|
||||
* that we have processed. if so, we skip that block for
|
||||
* now (write it at the end).
|
||||
|
@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
char *vi_Version =
|
||||
"$Id: vi.c,v 1.4 2001/04/16 15:46:44 andersen Exp $";
|
||||
"$Id: vi.c,v 1.5 2001/04/26 15:56:47 andersen Exp $";
|
||||
|
||||
/*
|
||||
* To compile for standalone use:
|
||||
@ -1745,7 +1745,7 @@ static void colon(Byte * buf)
|
||||
while (isblnk(*buf))
|
||||
buf++;
|
||||
strcpy((char *) args, (char *) buf);
|
||||
if (cmd[strlen((char *) cmd) - 1] == '!') {
|
||||
if (last_char_is((char *)cmd,'!')) {
|
||||
useforce = TRUE;
|
||||
cmd[strlen((char *) cmd) - 1] = '\0'; // get rid of !
|
||||
}
|
||||
|
@ -218,6 +218,7 @@ int klogctl(int type, char * b, int len);
|
||||
|
||||
char *xgetcwd(char *cwd);
|
||||
char *concat_path_file(const char *path, const char *filename);
|
||||
int last_char_is(const char *s, const int c);
|
||||
|
||||
typedef struct ar_headers_s {
|
||||
char *name;
|
||||
|
33
libbb/last_char_is.c
Normal file
33
libbb/last_char_is.c
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* busybox library eXtended function
|
||||
*
|
||||
* Copyright (C) 2001 Larry Doolittle, <ldoolitt@recycle.lbl.gov>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* Find out if the last character of a string matches the one given Don't
|
||||
* underrun the buffer if the string length is 0. Also avoids a possible
|
||||
* space-hogging inline of strlen() per usage.
|
||||
*/
|
||||
int last_char_is(const char *s, const int c)
|
||||
{
|
||||
int l = strlen(s);
|
||||
if (l==0) return 0;
|
||||
return (s[l-1] == c);
|
||||
}
|
@ -218,6 +218,7 @@ int klogctl(int type, char * b, int len);
|
||||
|
||||
char *xgetcwd(char *cwd);
|
||||
char *concat_path_file(const char *path, const char *filename);
|
||||
int last_char_is(const char *s, const int c);
|
||||
|
||||
typedef struct ar_headers_s {
|
||||
char *name;
|
||||
|
2
tar.c
2
tar.c
@ -706,7 +706,7 @@ static int readTarFile(int tarFd, int extractFlag, int listFlag,
|
||||
case REGTYPE0:
|
||||
/* If the name ends in a '/' then assume it is
|
||||
* supposed to be a directory, and fall through */
|
||||
if (header.name[strlen(header.name)-1] != '/') {
|
||||
if (last_char_is(header.name,'/')) {
|
||||
if (tarExtractRegularFile(&header, extractFlag, tostdoutFlag)==FALSE)
|
||||
errorFlag=TRUE;
|
||||
break;
|
||||
|
4
vi.c
4
vi.c
@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
char *vi_Version =
|
||||
"$Id: vi.c,v 1.4 2001/04/16 15:46:44 andersen Exp $";
|
||||
"$Id: vi.c,v 1.5 2001/04/26 15:56:47 andersen Exp $";
|
||||
|
||||
/*
|
||||
* To compile for standalone use:
|
||||
@ -1745,7 +1745,7 @@ static void colon(Byte * buf)
|
||||
while (isblnk(*buf))
|
||||
buf++;
|
||||
strcpy((char *) args, (char *) buf);
|
||||
if (cmd[strlen((char *) cmd) - 1] == '!') {
|
||||
if (last_char_is((char *)cmd,'!')) {
|
||||
useforce = TRUE;
|
||||
cmd[strlen((char *) cmd) - 1] = '\0'; // get rid of !
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user