Subject: Re: [PATCH] selftests/powerpc: Add a test of sigreturn vs VDSO

From: Nathan Lynch <[email-masked]>
Date: Fri, 06 Mar 2020 12:31:12 -0600

Nathan Lynch <[email-masked]> writes:
> Michael Ellerman <[email-masked]> writes:
>
>> +static int search_proc_maps(char *needle, unsigned long *low, unsigned long *high)
>
>                                ^^ const?
>                                
>> +{
>> +	unsigned long start, end;
>> +	static char buf[4096];
>> +	char name[128];
>> +	FILE *f;
>> +	int rc = -1;
>> +
>> +	f = fopen("/proc/self/maps", "r");
>> +	if (!f) {
>> +		perror("fopen");
>> +		return -1;
>> +	}
>> +
>> +	while (fgets(buf, sizeof(buf), f)) {
>> +		rc = sscanf(buf, "%lx-%lx %*c%*c%*c%*c %*x %*d:%*d %*d %127s\n",
>> +			    &start, &end, name);
>
> I suspect it doesn't matter in practice for this particular test, but
> since this looks like a generally useful function that could gain users
> in the future: does this spuriously fail if the matching line straddles
> a 4096-byte boundary? Maybe fscanf(3) should be used instead?

Or maybe I should read the fgets man page more closely :-)

  "Reading stops after an EOF or a newline."

Sorry for the noise.