baboom09 / sma-bluetooth

Automatically exported from code.google.com/p/sma-bluetooth
0 stars 0 forks source link

Segmentation Fault when string file path not found #107

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. In the config file set the "file" variable to a nonexistant file
2. run smatool

What is the expected output? What do you see instead?

Program Segfaults, due to fopen return vale not being checked.

Patch:

diff -r 5b25c83a1efc smatool.c
--- a/smatool.c Fri Oct 19 20:02:37 2012 +1100
+++ b/smatool.c Sat Nov 03 11:17:51 2012 +0000
@@ -804,7 +804,11 @@

    data_follows = 0;

-   fp=fopen(conf->File,"r");
+   if(( fp=fopen(conf->File,"r")) == (FILE *)NULL )
+   {
+      printf( "Error! Could not open file %s\n", conf->File );
+      exit( -1 ); //Could not open file
+   }

    while (!feof(fp)){
        if (fgets(line,400,fp) != NULL){                                //read line from smatool.conf

Original issue reported on code.google.com by coli...@gmail.com on 3 Nov 2012 at 1:22