Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocfs2console: array index out of bounds risk in testing code #62

Open
Byte-Jerry opened this issue Nov 13, 2023 · 0 comments
Open

ocfs2console: array index out of bounds risk in testing code #62

Byte-Jerry opened this issue Nov 13, 2023 · 0 comments

Comments

@Byte-Jerry
Copy link

There is a risk of array index out of bounds in the main functions of files blkid/cache.c, blkid/save.c, and blkid/read.c. When argc is greater than 2, the test program prints an error log and exits. If the second parameter is not entered when executing the command, argc is 1 and the parameter verification can be passed. In the following code, an array index out of bounds error occurs when using argv[1] to obtain a value.

For example, in the code in blkid/save.c, if argc equals 1, the array index is out of bounds on line 182.

#ifdef TEST_PROGRAM
int main(int argc, char **argv)
{
	blkid_cache cache = NULL;
	int ret;

	blkid_debug_mask = DEBUG_ALL;
	if (argc > 2) {
		fprintf(stderr, "Usage: %s [filename]\n"
			"Test loading/saving a cache (filename)\n", argv[0]);
		exit(1);
	}

	if ((ret = blkid_get_cache(&cache, "/dev/null")) != 0) {
		fprintf(stderr, "%s: error creating cache (%d)\n",
			argv[0], ret);
		exit(1);
	}
	if ((ret = blkid_probe_all(cache)) < 0) {
		fprintf(stderr, "error (%d) probing devices\n", ret);
		exit(1);
	}
	cache->bic_filename = blkid_strdup(argv[1]); //  line 182
	
	if ((ret = blkid_flush_cache(cache)) < 0) {
		fprintf(stderr, "error (%d) saving cache\n", ret);
		exit(1);
	}

	blkid_put_cache(cache);

	return ret;
}
#endif

I think the '>' in these main functions should be replaced with '<', which means the number of parameters must be greater than or equal to 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant