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>
This commit is contained in:
parent
84f6def072
commit
57dc3c7b4c
@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
//#include <features.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#ifndef _PATH_SHADOW
|
#ifndef _PATH_SHADOW
|
||||||
@ -1000,7 +999,6 @@ static int bb__parsespent(void *data, char *line)
|
|||||||
if (*endptr != ':') {
|
if (*endptr != ':') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*line++ = '\0';
|
*line++ = '\0';
|
||||||
@ -1022,15 +1020,16 @@ static int bb__parsespent(void *data, char *line)
|
|||||||
static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data,
|
static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data,
|
||||||
char *__restrict line_buff, size_t buflen, FILE *f)
|
char *__restrict line_buff, size_t buflen, FILE *f)
|
||||||
{
|
{
|
||||||
int line_len;
|
|
||||||
int skip;
|
int skip;
|
||||||
int rv = ERANGE;
|
int rv = ERANGE;
|
||||||
|
|
||||||
if (buflen < PWD_BUFFER_SIZE) {
|
if (buflen < PWD_BUFFER_SIZE) {
|
||||||
errno = rv;
|
errno = rv;
|
||||||
} else {
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
skip = 0;
|
skip = 0;
|
||||||
do {
|
while (1) {
|
||||||
if (!fgets(line_buff, buflen, f)) {
|
if (!fgets(line_buff, buflen, f)) {
|
||||||
if (feof(f)) {
|
if (feof(f)) {
|
||||||
rv = ENOENT;
|
rv = ENOENT;
|
||||||
@ -1038,16 +1037,21 @@ static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
line_len = strlen(line_buff) - 1; /* strlen() must be > 0. */
|
{
|
||||||
if (line_buff[line_len] == '\n') {
|
int line_len = strlen(line_buff) - 1;
|
||||||
line_buff[line_len] = 0;
|
if (line_len >= 0 && line_buff[line_len] == '\n') {
|
||||||
} else if (line_len + 2 == buflen) { /* line too long */
|
line_buff[line_len] = '\0';
|
||||||
++skip;
|
} else
|
||||||
|
if (line_len + 2 == buflen) {
|
||||||
|
/* A start (or continuation) of overlong line */
|
||||||
|
skip = 1;
|
||||||
continue;
|
continue;
|
||||||
|
} /* else: a last line in the file, and it has no '\n' */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skip) {
|
if (skip) {
|
||||||
--skip;
|
/* This "line" is a remainder of overlong line, ignore */
|
||||||
|
skip = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1056,22 +1060,20 @@ static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data,
|
|||||||
|
|
||||||
/* Skip empty lines, comment lines, and lines with leading
|
/* Skip empty lines, comment lines, and lines with leading
|
||||||
* whitespace. */
|
* whitespace. */
|
||||||
if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) {
|
if (line_buff[0] != '\0' && line_buff[0] != '#' && !isspace(line_buff[0])) {
|
||||||
if (parserfunc == bb__parsegrent) { /* Do evil group hack. */
|
if (parserfunc == bb__parsegrent) {
|
||||||
/* The group entry parsing function needs to know where
|
/* Do evil group hack:
|
||||||
|
* The group entry parsing function needs to know where
|
||||||
* the end of the buffer is so that it can construct the
|
* the end of the buffer is so that it can construct the
|
||||||
* group member ptr table. */
|
* group member ptr table. */
|
||||||
((struct group *) data)->gr_name = line_buff + buflen;
|
((struct group *) data)->gr_name = line_buff + buflen;
|
||||||
}
|
}
|
||||||
|
if (parserfunc(data, line_buff) == 0) {
|
||||||
if (!parserfunc(data, line_buff)) {
|
|
||||||
rv = 0;
|
rv = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (1);
|
} /* while (1) */
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user