[ethtool] 12/20: ethtool.c: do_seeprom checks for params & stdin sanity

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Mon Mar 14 11:37:16 UTC 2016


This is an automated email from the git hooks/post-receive script.

benh pushed a commit to branch master
in repository ethtool.

commit b03c8b423469a931899f95037aa1e9b6ff24fd3c
Author: David Decotigny <decot at googlers.com>
Date:   Fri Mar 11 09:58:17 2016 -0800

    ethtool.c: do_seeprom checks for params & stdin sanity
    
    Tested:
      On qemu e1000:
      $ dd if=/dev/zero bs=2 count=5 | /mnt/ethtool -E eth0 length 9
      too much data from stdin
      $ dd if=/dev/zero bs=2 count=5 | /mnt/ethtool -E eth0 length 11
      not enough data from stdin
      $ dd if=/dev/zero bs=2 count=5 | /mnt/ethtool -E eth0 length 10
      Cannot set EEPROM data: Bad address
    
    Signed-off-by: David Decotigny <decot at googlers.com>
    [bwh: Reverse order of '1 != fread(...)' comparison]
    Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
---
 ethtool.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 5f20b88..0cd0d4f 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -2828,8 +2828,10 @@ static int do_seeprom(struct cmd_context *ctx)
 	if (seeprom_length == -1)
 		seeprom_length = drvinfo.eedump_len;
 
-	if (drvinfo.eedump_len < seeprom_offset + seeprom_length)
-		seeprom_length = drvinfo.eedump_len - seeprom_offset;
+	if (drvinfo.eedump_len < seeprom_offset + seeprom_length) {
+		fprintf(stderr, "offset & length out of bounds\n");
+		return 1;
+	}
 
 	eeprom = calloc(1, sizeof(*eeprom)+seeprom_length);
 	if (!eeprom) {
@@ -2844,8 +2846,18 @@ static int do_seeprom(struct cmd_context *ctx)
 	eeprom->data[0] = seeprom_value;
 
 	/* Multi-byte write: read input from stdin */
-	if (!seeprom_value_seen)
-		eeprom->len = fread(eeprom->data, 1, eeprom->len, stdin);
+	if (!seeprom_value_seen) {
+		if (fread(eeprom->data, eeprom->len, 1, stdin) != 1) {
+			fprintf(stderr, "not enough data from stdin\n");
+			free(eeprom);
+			return 75;
+		}
+		if ((fgetc(stdin) != EOF) || !feof(stdin)) {
+			fprintf(stderr, "too much data from stdin\n");
+			free(eeprom);
+			return 75;
+		}
+	}
 
 	err = send_ioctl(ctx, eeprom);
 	if (err < 0) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/ethtool.git



More information about the Kernel-svn-changes mailing list