mirror of https://github.com/vitalif/e2fsprogs
Check fgets(3) return value
When fgets() function fails, contents of the buffer is undefined. That is, fgets() return value needs to be checked, to avoid undefined behavior. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org> Signed-off-by: Theodore Ts'o <tytso@mit.edu>bitmap-optimize
parent
84d51a2e99
commit
d9039ae0ff
|
@ -789,7 +789,8 @@ static void modify_u8(char *com, const char *prompt,
|
||||||
|
|
||||||
sprintf(buf, format, *val);
|
sprintf(buf, format, *val);
|
||||||
printf("%30s [%s] ", prompt, buf);
|
printf("%30s [%s] ", prompt, buf);
|
||||||
fgets(buf, sizeof(buf), stdin);
|
if (!fgets(buf, sizeof(buf), stdin))
|
||||||
|
return;
|
||||||
if (buf[strlen (buf) - 1] == '\n')
|
if (buf[strlen (buf) - 1] == '\n')
|
||||||
buf[strlen (buf) - 1] = '\0';
|
buf[strlen (buf) - 1] = '\0';
|
||||||
if (!buf[0])
|
if (!buf[0])
|
||||||
|
@ -810,7 +811,8 @@ static void modify_u16(char *com, const char *prompt,
|
||||||
|
|
||||||
sprintf(buf, format, *val);
|
sprintf(buf, format, *val);
|
||||||
printf("%30s [%s] ", prompt, buf);
|
printf("%30s [%s] ", prompt, buf);
|
||||||
fgets(buf, sizeof(buf), stdin);
|
if (!fgets(buf, sizeof(buf), stdin))
|
||||||
|
return;
|
||||||
if (buf[strlen (buf) - 1] == '\n')
|
if (buf[strlen (buf) - 1] == '\n')
|
||||||
buf[strlen (buf) - 1] = '\0';
|
buf[strlen (buf) - 1] = '\0';
|
||||||
if (!buf[0])
|
if (!buf[0])
|
||||||
|
@ -831,7 +833,8 @@ static void modify_u32(char *com, const char *prompt,
|
||||||
|
|
||||||
sprintf(buf, format, *val);
|
sprintf(buf, format, *val);
|
||||||
printf("%30s [%s] ", prompt, buf);
|
printf("%30s [%s] ", prompt, buf);
|
||||||
fgets(buf, sizeof(buf), stdin);
|
if (!fgets(buf, sizeof(buf), stdin))
|
||||||
|
return;
|
||||||
if (buf[strlen (buf) - 1] == '\n')
|
if (buf[strlen (buf) - 1] == '\n')
|
||||||
buf[strlen (buf) - 1] = '\0';
|
buf[strlen (buf) - 1] = '\0';
|
||||||
if (!buf[0])
|
if (!buf[0])
|
||||||
|
|
|
@ -251,10 +251,8 @@ static int is_swap_device(const char *file)
|
||||||
if (!(f = fopen("/proc/swaps", "r")))
|
if (!(f = fopen("/proc/swaps", "r")))
|
||||||
return 0;
|
return 0;
|
||||||
/* Skip the first line */
|
/* Skip the first line */
|
||||||
fgets(buf, sizeof(buf), f);
|
if (fgets(buf, sizeof(buf), f))
|
||||||
while (!feof(f)) {
|
while (fgets(buf, sizeof(buf), f)) {
|
||||||
if (!fgets(buf, sizeof(buf), f))
|
|
||||||
break;
|
|
||||||
if ((cp = strchr(buf, ' ')) != NULL)
|
if ((cp = strchr(buf, ' ')) != NULL)
|
||||||
*cp = 0;
|
*cp = 0;
|
||||||
if ((cp = strchr(buf, '\t')) != NULL)
|
if ((cp = strchr(buf, '\t')) != NULL)
|
||||||
|
|
|
@ -71,8 +71,8 @@ void proceed_question(void)
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
fputs(_("Proceed anyway? (y,n) "), stdout);
|
fputs(_("Proceed anyway? (y,n) "), stdout);
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
fgets(buf, sizeof(buf), stdin);
|
if (!fgets(buf, sizeof(buf), stdin) ||
|
||||||
if (strchr(short_yes, buf[0]) == 0)
|
strchr(short_yes, buf[0]) == 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue