Powered by Linux
smatch on illumos & false positive — Semantic Matching Tool

smatch on illumos & false positive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I cloned smatch (ca3d9889352dabbd3dcd403cce3e702a56c7d2b2), and tried to run
it on my illumos-based [1] laptop.  There was one quick hack I had to do to
get it to run because `uname -m` is "i86pc" on both 32-bit and 64-bit x86.
(The machine is i86pc.)  `uname -p` spits out "i386" on both 32-bit and 64-bit.
(The processor is i386 compatible.)

diff --git a/cgcc b/cgcc
index c075e5f..26d10f0 100755
--- a/cgcc
+++ b/cgcc
@@ -271,7 +271,7 @@ sub add_specs {
 	chomp $os;
 	return &add_specs (lc $os);
     } elsif ($spec eq 'host_arch_specs') {
-	my $arch = `uname -m`;
+	my $arch = `uname -p`;
 	chomp $arch;
 	if ($arch =~ /^(i.?86|athlon)$/i) {
 	    return &add_specs ('i86');


Anyway, it builds and runs fine.  At this point.  It does however run into
something it doesn't know how to deal with.  Specifically, if I include
unistd.h, I get:

/usr/include/unistd.h:565:26: error: attribute '__returns_twice__': unknown attribute

This is because of:

extern pid_t vfork(void) __RETURNS_TWICE;                                                                 

It looks like there are other functions that are annotated with the same
attribute (getcontext, setjmp, etc.).



While I'm writing this email, I might as well point out a false positive
smatch told me about.  I have a program that takes an year and month as a 6
digit number (e.g., 201501) and I want double check that it's valid.  (The
first 4 digits look like a year and the last two digits look like a month
number.)  Later on, I use the month part to index into an array of month
names.  Here's a simplified test case:

#include <stdio.h>
#include <unistd.h>

static int validate_arch_id(int arch)
{
	int y = arch / 100;
	int m = arch % 100;

	return (m >= 1) && (m <= 12) && (y >= 1970) && (y < 2100);
}

int main(int argc, char **argv)
{
	static const char *months[12] = {
		"January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November",
		"December",
	};

	int arch = 201201; /* test */

	if (!validate_arch_id(arch))
		arch = 197001;

	printf("%s\n", months[(arch % 100) - 1]);

	return 0;
}


I get the following error:

test.c:25 main() error: buffer overflow 'months' 12 <= 98

Obviously, smatch doesn't realize that given the validation and optional
assignment to 197001, it will never overflow.


Jeff.

[1] an opensolaris fork

-- 
Bad pun of the week: The formula 1 control computer suffered from a race
condition
--
To unsubscribe from this list: send the line "unsubscribe smatch" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux