mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
limit the field width of 'scanf'
Fixes: #2121 Signed-off-by: Pengda Yang <daz-3ux@proton.me>
This commit is contained in:
parent
3c7d4fa013
commit
ddbb3dbd8d
13 changed files with 15 additions and 15 deletions
|
|
@ -54,7 +54,7 @@ mnt_info_t *get_cwd_mnt_info(void)
|
|||
|
||||
while (fgets(str, sizeof(str), f)) {
|
||||
char *hyphen = strchr(str, '-');
|
||||
ret = sscanf(str, "%i %i %u:%u %s %s", &mnt_id, &parent_mnt_id, &kmaj, &kmin, root, mountpoint);
|
||||
ret = sscanf(str, "%i %i %u:%u %4095s %4095s", &mnt_id, &parent_mnt_id, &kmaj, &kmin, root, mountpoint);
|
||||
if (ret != 6 || !hyphen)
|
||||
goto err;
|
||||
ret = sscanf(hyphen + 1, " %ms", &fsname);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ int checkprofile(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
len = fscanf(f, "%[^ \n]s", profile);
|
||||
len = fscanf(f, "%1023[^ \n]s", profile);
|
||||
fclose(f);
|
||||
if (len != 1) {
|
||||
fail("wrong number of items scanned %d", len);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ static int checkprofile(pid_t pid, char *expected)
|
|||
return -1;
|
||||
}
|
||||
|
||||
len = fscanf(f, "%[^ \n]s", profile);
|
||||
len = fscanf(f, "%1023[^ \n]s", profile);
|
||||
fclose(f);
|
||||
if (len != 1) {
|
||||
fail("wrong number of items scanned %d", len);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ int main(int argc, char **argv)
|
|||
if (!s)
|
||||
continue;
|
||||
|
||||
sscanf(paux, "%*d %*d %*d:%*d %*s %s", aux);
|
||||
sscanf(paux, "%*d %*d %*d:%*d %*s %1023s", aux);
|
||||
test_msg("found cgroup at %s\n", aux);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ bool test_exists(char *mountinfo_line, char *path)
|
|||
char aux[1024], paux[1024];
|
||||
struct stat st;
|
||||
|
||||
sscanf(mountinfo_line, "%*d %*d %*d:%*d %*s %s", aux);
|
||||
sscanf(mountinfo_line, "%*d %*d %*d:%*d %*s %1023s", aux);
|
||||
test_msg("found cgroup at %s\n", aux);
|
||||
|
||||
ssprintf(paux, "%s/%s", aux, path);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ int main(int argc, char **argv)
|
|||
if (!pos)
|
||||
continue;
|
||||
|
||||
result = sscanf(pos, " - %*s %*s %s", opts);
|
||||
result = sscanf(pos, " - %*s %*s %1023s", opts);
|
||||
if (result != 1) {
|
||||
fail("Not able to sscanf line from mountinfo");
|
||||
goto out;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ static int check_file_lock(int fd, char *expected_type, char *expected_option, u
|
|||
memset(fl_type, 0, sizeof(fl_type));
|
||||
memset(fl_option, 0, sizeof(fl_option));
|
||||
|
||||
num = sscanf(buf, "%*s %*d:%s %s %s %d %x:%x:%ld %*d %*s", fl_flag, fl_type, fl_option, &fl_owner, &maj,
|
||||
num = sscanf(buf, "%*s %*d:%15s %15s %15s %d %x:%x:%ld %*d %*s", fl_flag, fl_type, fl_option, &fl_owner, &maj,
|
||||
&min, &i_no);
|
||||
if (num < 7) {
|
||||
pr_err("Invalid lock info\n");
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ static int check_file_lock(pid_t pid, pid_t child, int fd, char *expected_type,
|
|||
memset(fl_type, 0, sizeof(fl_type));
|
||||
memset(fl_option, 0, sizeof(fl_option));
|
||||
|
||||
num = sscanf(buf, "%*s %*d:%s %s %s %d", fl_flag, fl_type, fl_option, &fl_owner);
|
||||
num = sscanf(buf, "%*s %*d:%15s %15s %15s %d", fl_flag, fl_type, fl_option, &fl_owner);
|
||||
if (num < 4) {
|
||||
pr_perror("Invalid lock info.");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ static int check_file_lock(pid_t pid, pid_t child, int fd, char *expected_type,
|
|||
memset(fl_type, 0, sizeof(fl_type));
|
||||
memset(fl_option, 0, sizeof(fl_option));
|
||||
|
||||
num = sscanf(buf, "%*s %*d:%s %s %s %d", fl_flag, fl_type, fl_option, &fl_owner);
|
||||
num = sscanf(buf, "%*s %*d:%15s %15s %15s %d", fl_flag, fl_type, fl_option, &fl_owner);
|
||||
if (num < 4) {
|
||||
pr_perror("Invalid lock info.");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ static int check_file_locks(pid_t child_pid, int fd, int child_fd)
|
|||
continue;
|
||||
test_msg("c: %s", buf);
|
||||
|
||||
num = sscanf(buf, "%*s %*d:%s %s %s %d %*02x:%*02x:%*d %*d %*s", fl_flag, fl_type, fl_option,
|
||||
num = sscanf(buf, "%*s %*d:%15s %15s %15s %d %*02x:%*02x:%*d %*d %*s", fl_flag, fl_type, fl_option,
|
||||
&fl_owner);
|
||||
|
||||
if (num < 4) {
|
||||
|
|
|
|||
|
|
@ -414,7 +414,7 @@ static int check_stable_secret(struct test_conf *tc)
|
|||
return -1;
|
||||
}
|
||||
|
||||
ret = fscanf(fp, "%s", val);
|
||||
ret = fscanf(fp, "%200s", val);
|
||||
if (ret != 1) {
|
||||
pr_perror("fscanf");
|
||||
fclose(fp);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ static int parse_ofd_lock(char *buf, struct flock *lck)
|
|||
if (strncmp(buf, "lock:\t", 6) != 0)
|
||||
return 1; /* isn't lock, skip record */
|
||||
|
||||
num = sscanf(buf, "%*s %*d: %s %s %s %*d %*x:%*x:%*d %lld %s", fl_flag, fl_type, fl_option, &start, fl_end);
|
||||
num = sscanf(buf, "%*s %*d: %9s %14s %9s %*d %*x:%*x:%*d %lld %31s", fl_flag, fl_type, fl_option, &start, fl_end);
|
||||
|
||||
if (num < 4) {
|
||||
pr_err("Invalid lock info %s\n", buf);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue