PVS V1010: access before start of buffer after fgets
Change-Id: I8cfa1e8a3c8dd8c2837e51756ac3eeaea1e756f0 Reviewed-on: https://review.haiku-os.org/c/1639 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
a63a6eb9bc
commit
91ec679f17
+4
-2
@@ -238,8 +238,10 @@ main(int argc, const char** argv)
|
||||
// read file names from stdin
|
||||
char name[B_PATH_NAME_LENGTH];
|
||||
while (fgets(name, sizeof(name), stdin) != NULL) {
|
||||
name[strlen(name) - 1] = '\0';
|
||||
// remove trailing '\n'
|
||||
if (name[0] != '\0') {
|
||||
name[strlen(name) - 1] = '\0';
|
||||
// remove trailing '\n'
|
||||
}
|
||||
if (process_file(name) != B_OK)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
+1
-1
@@ -284,7 +284,7 @@ do_input(void)
|
||||
|
||||
while(fgets(buff, 256, stdin) != NULL)
|
||||
{
|
||||
if (buff[strlen(buff)-1] == '\n')
|
||||
if (buff[0] != '\0' && buff[strlen(buff)-1] == '\n')
|
||||
buff[strlen(buff)-1] = '\0'; /* kill the newline character */
|
||||
|
||||
for(ptr=buff; isspace(*ptr) && *ptr; ptr++)
|
||||
|
||||
@@ -38,7 +38,7 @@ getpass(const char *prompt)
|
||||
if (fgets(password, sizeof(password), stdin) != NULL) {
|
||||
size_t length = strlen(password);
|
||||
|
||||
if (password[length - 1] == '\n')
|
||||
if (length > 0 && (password[length - 1] == '\n'))
|
||||
password[length - 1] = '\0';
|
||||
|
||||
if (changed) {
|
||||
|
||||
Reference in New Issue
Block a user