diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-31 10:24:37 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-31 10:24:37 +0200 |
commit | 57dc3c7b4c31d3c67104f3a40c3b106483801961 (patch) | |
tree | 1999a47bcb5eb30dac4bef67e375381f5311aea3 | |
parent | 84f6def072778e30bbaa7c98256e7e421a3c5bc4 (diff) | |
download | busybox-w32-57dc3c7b4c31d3c67104f3a40c3b106483801961.tar.gz busybox-w32-57dc3c7b4c31d3c67104f3a40c3b106483801961.tar.bz2 busybox-w32-57dc3c7b4c31d3c67104f3a40c3b106483801961.zip |
libpwdgrp: can't depend on strlen(line_buff) != 0
function old new delta
bb__pgsreader 188 202 +14
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libpwdgrp/pwd_grp.c | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index 947f48d43..5b0d6b245 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c | |||
@@ -19,7 +19,6 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "libbb.h" | 21 | #include "libbb.h" |
22 | //#include <features.h> | ||
23 | #include <assert.h> | 22 | #include <assert.h> |
24 | 23 | ||
25 | #ifndef _PATH_SHADOW | 24 | #ifndef _PATH_SHADOW |
@@ -1000,7 +999,6 @@ static int bb__parsespent(void *data, char *line) | |||
1000 | if (*endptr != ':') { | 999 | if (*endptr != ':') { |
1001 | break; | 1000 | break; |
1002 | } | 1001 | } |
1003 | |||
1004 | } | 1002 | } |
1005 | 1003 | ||
1006 | *line++ = '\0'; | 1004 | *line++ = '\0'; |
@@ -1022,56 +1020,60 @@ static int bb__parsespent(void *data, char *line) | |||
1022 | static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data, | 1020 | static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data, |
1023 | char *__restrict line_buff, size_t buflen, FILE *f) | 1021 | char *__restrict line_buff, size_t buflen, FILE *f) |
1024 | { | 1022 | { |
1025 | int line_len; | ||
1026 | int skip; | 1023 | int skip; |
1027 | int rv = ERANGE; | 1024 | int rv = ERANGE; |
1028 | 1025 | ||
1029 | if (buflen < PWD_BUFFER_SIZE) { | 1026 | if (buflen < PWD_BUFFER_SIZE) { |
1030 | errno = rv; | 1027 | errno = rv; |
1031 | } else { | 1028 | return rv; |
1032 | skip = 0; | 1029 | } |
1033 | do { | ||
1034 | if (!fgets(line_buff, buflen, f)) { | ||
1035 | if (feof(f)) { | ||
1036 | rv = ENOENT; | ||
1037 | } | ||
1038 | break; | ||
1039 | } | ||
1040 | 1030 | ||
1041 | line_len = strlen(line_buff) - 1; /* strlen() must be > 0. */ | 1031 | skip = 0; |
1042 | if (line_buff[line_len] == '\n') { | 1032 | while (1) { |
1043 | line_buff[line_len] = 0; | 1033 | if (!fgets(line_buff, buflen, f)) { |
1044 | } else if (line_len + 2 == buflen) { /* line too long */ | 1034 | if (feof(f)) { |
1045 | ++skip; | 1035 | rv = ENOENT; |
1046 | continue; | ||
1047 | } | 1036 | } |
1037 | break; | ||
1038 | } | ||
1048 | 1039 | ||
1049 | if (skip) { | 1040 | { |
1050 | --skip; | 1041 | int line_len = strlen(line_buff) - 1; |
1042 | if (line_len >= 0 && line_buff[line_len] == '\n') { | ||
1043 | line_buff[line_len] = '\0'; | ||
1044 | } else | ||
1045 | if (line_len + 2 == buflen) { | ||
1046 | /* A start (or continuation) of overlong line */ | ||
1047 | skip = 1; | ||
1051 | continue; | 1048 | continue; |
1052 | } | 1049 | } /* else: a last line in the file, and it has no '\n' */ |
1050 | } | ||
1053 | 1051 | ||
1054 | /* NOTE: glibc difference - glibc strips leading whitespace from | 1052 | if (skip) { |
1055 | * records. We do not allow leading whitespace. */ | 1053 | /* This "line" is a remainder of overlong line, ignore */ |
1056 | 1054 | skip = 0; | |
1057 | /* Skip empty lines, comment lines, and lines with leading | 1055 | continue; |
1058 | * whitespace. */ | 1056 | } |
1059 | if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) { | ||
1060 | if (parserfunc == bb__parsegrent) { /* Do evil group hack. */ | ||
1061 | /* The group entry parsing function needs to know where | ||
1062 | * the end of the buffer is so that it can construct the | ||
1063 | * group member ptr table. */ | ||
1064 | ((struct group *) data)->gr_name = line_buff + buflen; | ||
1065 | } | ||
1066 | 1057 | ||
1067 | if (!parserfunc(data, line_buff)) { | 1058 | /* NOTE: glibc difference - glibc strips leading whitespace from |
1068 | rv = 0; | 1059 | * records. We do not allow leading whitespace. */ |
1069 | break; | 1060 | |
1070 | } | 1061 | /* Skip empty lines, comment lines, and lines with leading |
1062 | * whitespace. */ | ||
1063 | if (line_buff[0] != '\0' && line_buff[0] != '#' && !isspace(line_buff[0])) { | ||
1064 | if (parserfunc == bb__parsegrent) { | ||
1065 | /* Do evil group hack: | ||
1066 | * The group entry parsing function needs to know where | ||
1067 | * the end of the buffer is so that it can construct the | ||
1068 | * group member ptr table. */ | ||
1069 | ((struct group *) data)->gr_name = line_buff + buflen; | ||
1071 | } | 1070 | } |
1072 | } while (1); | 1071 | if (parserfunc(data, line_buff) == 0) { |
1073 | 1072 | rv = 0; | |
1074 | } | 1073 | break; |
1074 | } | ||
1075 | } | ||
1076 | } /* while (1) */ | ||
1075 | 1077 | ||
1076 | return rv; | 1078 | return rv; |
1077 | } | 1079 | } |