Browse Source

Verify fread(), fwrite(), and system() return values

These were starting to trigger compiler warning with recent glibc header
files and gcc.
Jouni Malinen 16 years ago
parent
commit
308a4ec81a
3 changed files with 18 additions and 5 deletions
  1. 8 2
      src/eap_peer/eap_fast_pac.c
  2. 6 1
      src/utils/os_unix.c
  3. 4 2
      wpa_supplicant/wpa_cli.c

+ 8 - 2
src/eap_peer/eap_fast_pac.c

@@ -533,6 +533,8 @@ static void eap_fast_write(char **buf, char **pos, size_t *buf_len,
 static int eap_fast_write_pac(struct eap_sm *sm, const char *pac_file,
 			      char *buf, size_t len)
 {
+	int ret = 0;
+
 	if (os_strncmp(pac_file, "blob://", 7) == 0) {
 		struct wpa_config_blob *blob;
 		blob = os_zalloc(sizeof(*blob));
@@ -555,12 +557,16 @@ static int eap_fast_write_pac(struct eap_sm *sm, const char *pac_file,
 				   "file '%s' for writing", pac_file);
 			return -1;
 		}
-		fwrite(buf, 1, len, f);
+		if (fwrite(buf, 1, len, f) != len) {
+			wpa_printf(MSG_INFO, "EAP-FAST: Failed to write all "
+				   "PACs into '%s'", pac_file);
+			ret = -1;
+		}
 		os_free(buf);
 		fclose(f);
 	}
 
-	return 0;
+	return ret;
 }
 
 

+ 6 - 1
src/utils/os_unix.c

@@ -220,7 +220,12 @@ char * os_readfile(const char *name, size_t *len)
 		return NULL;
 	}
 
-	fread(buf, 1, *len, f);
+	if (fread(buf, 1, *len, f) != *len) {
+		fclose(f);
+		free(buf);
+		return NULL;
+	}
+
 	fclose(f);
 
 	return buf;

+ 4 - 2
wpa_supplicant/wpa_cli.c

@@ -1152,6 +1152,7 @@ static int wpa_cli_exec(const char *program, const char *arg1,
 	char *cmd;
 	size_t len;
 	int res;
+	int ret = 0;
 
 	len = os_strlen(program) + os_strlen(arg1) + os_strlen(arg2) + 3;
 	cmd = os_malloc(len);
@@ -1164,11 +1165,12 @@ static int wpa_cli_exec(const char *program, const char *arg1,
 	}
 	cmd[len - 1] = '\0';
 #ifndef _WIN32_WCE
-	system(cmd);
+	if (system(cmd) < 0)
+		ret = -1;
 #endif /* _WIN32_WCE */
 	os_free(cmd);
 
-	return 0;
+	return ret;
 }