File rtl-sdr-0011-improve-rtl_power--scanning-range-parsing.patch of Package rtl-sdr

From f2a9a81c4be95a6e9da97ec784f893d98a43f289 Mon Sep 17 00:00:00 2001
From: "A. Maitland Bottoms" <bottoms@debian.org>
Date: Thu, 24 Aug 2017 05:27:57 -0400
Subject: [PATCH] rtl_fm/rtl_power: Improve scanning range parsing

---
 src/rtl_fm.c    | 13 +++++++++++++
 src/rtl_power.c |  8 ++++++++
 2 files changed, 21 insertions(+)

diff --git a/src/rtl_fm.c b/src/rtl_fm.c
index b163979..283542d 100644
--- a/src/rtl_fm.c
+++ b/src/rtl_fm.c
@@ -926,8 +926,21 @@ void frequency_range(struct controller_state *s, char *arg)
 	int i;
 	start = arg;
 	stop = strchr(start, ':') + 1;
+	if (stop == (char *)1) { // no stop or step given
+		s->freqs[s->freq_len] = (uint32_t) atofs(start);
+		s->freq_len++;
+		return;
+	}
 	stop[-1] = '\0';
 	step = strchr(stop, ':') + 1;
+	if (step == (char *)1) { // no step given
+		s->freqs[s->freq_len] = (uint32_t) atofs(start);
+		s->freq_len++;
+		s->freqs[s->freq_len] = (uint32_t) atofs(stop);
+		s->freq_len++;
+		stop[-1] = ':';
+		return;
+	}
 	step[-1] = '\0';
 	for(i=(int)atofs(start); i<=(int)atofs(stop); i+=(int)atofs(step))
 	{
diff --git a/src/rtl_power.c b/src/rtl_power.c
index 625d818..6204de2 100644
--- a/src/rtl_power.c
+++ b/src/rtl_power.c
@@ -437,8 +437,16 @@ void frequency_range(char *arg, double crop)
 	/* hacky string parsing */
 	start = arg;
 	stop = strchr(start, ':') + 1;
+	if (stop == (char *)1) {
+		fprintf(stderr, "Bad frequency range specification: %s\n", arg);
+		exit(1);
+	}
 	stop[-1] = '\0';
 	step = strchr(stop, ':') + 1;
+	if (step == (char *)1) {
+		fprintf(stderr, "Bad frequency range specification: %s\n", arg);
+		exit(1);
+	}
 	step[-1] = '\0';
 	lower = (int)atofs(start);
 	upper = (int)atofs(stop);
openSUSE Build Service is sponsored by