49 lines
1.4 KiB
Diff
49 lines
1.4 KiB
Diff
|
|
From af3e50dbe29e6ecf5ada3ff4dad12ac19f426d8d Mon Sep 17 00:00:00 2001
|
||
|
|
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com>
|
||
|
|
Date: Sun, 12 Aug 2018 12:15:45 +0200
|
||
|
|
Subject: [PATCH 83/86] device_info: Fix parsing partition number
|
||
|
|
|
||
|
|
Ensures that it is always valid number which does not overflow or
|
||
|
|
underflow.
|
||
|
|
---
|
||
|
|
src/device_info.c | 9 ++++++---
|
||
|
|
1 file changed, 6 insertions(+), 3 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/device_info.c b/src/device_info.c
|
||
|
|
index cd57388..a8764d7 100644
|
||
|
|
--- a/src/device_info.c
|
||
|
|
+++ b/src/device_info.c
|
||
|
|
@@ -44,6 +44,8 @@
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
+#include <errno.h>
|
||
|
|
+#include <ctype.h>
|
||
|
|
|
||
|
|
#include "blkdev.h"
|
||
|
|
#include "device_info.h"
|
||
|
|
@@ -109,7 +111,7 @@ static int udev_fill_info(struct device_info *info, struct stat *stat)
|
||
|
|
char holders_path[PATH_MAX + 1];
|
||
|
|
DIR *holders_dir;
|
||
|
|
struct dirent *dir_entry;
|
||
|
|
- unsigned long number;
|
||
|
|
+ long number;
|
||
|
|
char *endptr;
|
||
|
|
|
||
|
|
if (device_info_verbose >= 3)
|
||
|
|
@@ -227,8 +229,9 @@ static int udev_fill_info(struct device_info *info, struct stat *stat)
|
||
|
|
if (device_info_verbose >= 3)
|
||
|
|
printf("attribute \"partition\" is \"%s\"\n", attr);
|
||
|
|
|
||
|
|
- number = strtoul(attr, &endptr, 10);
|
||
|
|
- if (!*endptr)
|
||
|
|
+ errno = 0;
|
||
|
|
+ number = strtol(attr, &endptr, 10);
|
||
|
|
+ if (*attr && !isspace(*attr) && !*endptr && !errno && number >= 0 && number <= INT_MAX)
|
||
|
|
info->partition = number;
|
||
|
|
} else {
|
||
|
|
printf("attribute \"partition\" not found\n");
|
||
|
|
--
|
||
|
|
1.8.3.1
|
||
|
|
|