Check the return value of fscanf() when reading a PID file.
[oweals/tinc.git] / lib / pidfile.c
index 830d3f358d6a08c65404f193b89e1e9a6066b879..dd6788a6539fea41ed1ce2790ab3446d795f5055 100644 (file)
@@ -41,7 +41,8 @@ pid_t read_pid (char *pidfile)
 
   if (!(f=fopen(pidfile,"r")))
     return 0;
-  fscanf(f,"%ld", &pid);
+  if(fscanf(f,"%ld", &pid) != 1)
+    pid = 0;
   fclose(f);
   return pid;
 }