diff options
Diffstat (limited to 'sutils')
| -rw-r--r-- | sutils/0001-essid.c-change-put_status-to-return-int.patch | 58 | ||||
| -rw-r--r-- | sutils/0002-essid.c-take-some-care.patch | 38 | ||||
| -rw-r--r-- | sutils/0003-volume.c-take-some-care.patch | 55 | ||||
| -rw-r--r-- | sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch | 46 | ||||
| -rw-r--r-- | sutils/APKBUILD | 20 |
5 files changed, 212 insertions, 5 deletions
diff --git a/sutils/0001-essid.c-change-put_status-to-return-int.patch b/sutils/0001-essid.c-change-put_status-to-return-int.patch new file mode 100644 index 0000000..c9882a8 --- /dev/null +++ b/sutils/0001-essid.c-change-put_status-to-return-int.patch @@ -0,0 +1,58 @@ +From dcc55996ba47675e3c2d1cd562972be370a0531d Mon Sep 17 00:00:00 2001 +From: John Vogel <jvogel4@stny.rr.com> +Date: Mon, 9 Oct 2023 10:29:14 -0400 +Subject: [PATCH 1/4] essid.c: change put_status to return int + +Modify main loop to break out if error and return failure if so. +--- + essid.c | 15 ++++++++++----- + 1 file changed, 10 insertions(+), 5 deletions(-) + +diff --git a/essid.c b/essid.c +index 4a768f0..de45164 100644 +--- a/essid.c ++++ b/essid.c +@@ -19,17 +19,19 @@ char *format = FORMAT; + int interval = INTERVAL; + char name[IW_ESSID_MAX_SIZE + 1] = {0}; + +-void put_status(int fd, struct iwreq *rqt) ++int put_status(int fd, struct iwreq *rqt) + { + rqt->u.essid.pointer = name; + rqt->u.essid.length = IW_ESSID_MAX_SIZE + 1; + if (ioctl(fd, SIOCGIWESSID, rqt) == -1) { + perror("ioctl"); +- exit(EXIT_FAILURE); ++ return -1; + } + printf(format, name); + printf("\n"); + fflush(stdout); ++ ++ return 0; + } + + int main(int argc, char *argv[]) +@@ -71,12 +73,15 @@ int main(int argc, char *argv[]) + + if (snoop) + while (true) { +- put_status(sock_fd, &request); ++ if (put_status(sock_fd, &request) == -1) { ++ name[0] = '\0'; ++ break; ++ } + sleep(interval); +- name[0] = '\0'; + } + else +- put_status(sock_fd, &request); ++ if (put_status(sock_fd, &request) == -1) ++ name[0] = '\0'; + + close(sock_fd); + if (strlen(name) > 0) +-- +2.42.0 + diff --git a/sutils/0002-essid.c-take-some-care.patch b/sutils/0002-essid.c-take-some-care.patch new file mode 100644 index 0000000..b640699 --- /dev/null +++ b/sutils/0002-essid.c-take-some-care.patch @@ -0,0 +1,38 @@ +From fc42d8237fa49de90fadbc515c8828ee0f57da1b Mon Sep 17 00:00:00 2001 +From: John Vogel <jvogel4@stny.rr.com> +Date: Mon, 9 Oct 2023 10:32:34 -0400 +Subject: [PATCH 2/4] essid.c: take some care + +Copy the interface name with strcpy, not sprint. +Return from put_status with error if the format is not able to +handle a string param. +--- + essid.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/essid.c b/essid.c +index de45164..3050bd7 100644 +--- a/essid.c ++++ b/essid.c +@@ -21,6 +21,9 @@ char name[IW_ESSID_MAX_SIZE + 1] = {0}; + + int put_status(int fd, struct iwreq *rqt) + { ++ if (strstr(format, "%s") == NULL) ++ return -1; ++ + rqt->u.essid.pointer = name; + rqt->u.essid.length = IW_ESSID_MAX_SIZE + 1; + if (ioctl(fd, SIOCGIWESSID, rqt) == -1) { +@@ -64,7 +67,7 @@ int main(int argc, char *argv[]) + struct iwreq request; + int sock_fd; + memset(&request, 0, sizeof(struct iwreq)); +- sprintf(request.ifr_name, interface); ++ strncpy(request.ifr_name, interface, strlen(interface)); + + if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + perror("socket"); +-- +2.42.0 + diff --git a/sutils/0003-volume.c-take-some-care.patch b/sutils/0003-volume.c-take-some-care.patch new file mode 100644 index 0000000..1ad3c28 --- /dev/null +++ b/sutils/0003-volume.c-take-some-care.patch @@ -0,0 +1,55 @@ +From 9c99628bb8a13ce825cf6ee7a3544a40b5527068 Mon Sep 17 00:00:00 2001 +From: John Vogel <jvogel4@stny.rr.com> +Date: Mon, 9 Oct 2023 10:36:06 -0400 +Subject: [PATCH 3/4] volume.c: take some care + +Use strcpy instead of sprintf. +Be more careful with the printf format. +--- + volume.c | 19 +++++++++++++------ + 1 file changed, 13 insertions(+), 6 deletions(-) + +diff --git a/volume.c b/volume.c +index 8117279..b0c49ee 100644 +--- a/volume.c ++++ b/volume.c +@@ -25,6 +25,8 @@ int put_infos(int vol_min, int vol_max, + int volume; + int volume_percent; + bool mute_switch; ++ bool print_switch_state; ++ bool print_volume_percent; + char switch_state[4]; + + snd_hctl_elem_read(volume_elem, volume_ctl); +@@ -36,16 +38,21 @@ int put_infos(int vol_min, int vol_max, + volume_percent = (int)(100.0f * ((float)volume - vol_min) / (vol_max - vol_min)); + + if (mute_switch == true) +- sprintf(switch_state, "on"); ++ strcpy(switch_state, "on"); + else +- sprintf(switch_state, "off"); ++ strcpy(switch_state, "off"); + +- if (strstr(format, "%s") == NULL) +- printf(format, volume_percent); +- else if (strstr(format, "%i") == NULL) ++ print_switch_state = (strstr(format, "%s") == NULL) ? false : true; ++ print_volume_percent = (strstr(format, "%i") == NULL) ? false : true; ++ ++ if (print_switch_state && print_volume_percent) ++ printf(format, switch_state, volume_percent); ++ else if (print_switch_state) + printf(format, switch_state); ++ else if (print_volume_percent) ++ printf(format, volume_percent); + else +- printf(format, switch_state, volume_percent); ++ exit(EXIT_FAILURE); + printf("\n"); + fflush(stdout); + +-- +2.42.0 + diff --git a/sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch b/sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch new file mode 100644 index 0000000..7fc8ee3 --- /dev/null +++ b/sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch @@ -0,0 +1,46 @@ +From d3b11514c22943587e76def34c48655c78cd9610 Mon Sep 17 00:00:00 2001 +From: John Vogel <jvogel4@stny.rr.com> +Date: Mon, 9 Oct 2023 10:39:19 -0400 +Subject: [PATCH 4/4] battery.c: be more careful with the printf format + +--- + battery.c | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/battery.c b/battery.c +index 20307e5..0770619 100644 +--- a/battery.c ++++ b/battery.c +@@ -26,6 +26,7 @@ int put_infos(char *path, char *format) + char status[MAXLEN] = {0}; + int capacity = -1; + bool found_status = false, found_capacity = false; ++ bool print_status = false, print_capacity = false; + while (fgets(line, sizeof(line), bf) != NULL) { + char *key = strtok(line, TOKSEP); + if (key != NULL) { +@@ -43,12 +44,17 @@ int put_infos(char *path, char *format) + fprintf(stderr, "The battery information is missing.\n"); + return EXIT_FAILURE; + } else { +- if (strstr(format, "%s") == NULL) +- printf(format, capacity); +- else if (strstr(format, "%i") == NULL) ++ print_status = (strstr(format, "%s") == NULL) ? false : true; ++ print_capacity = (strstr(format, "%i") == NULL) ? false : true; ++ ++ if (print_status && print_capacity) ++ printf(format, status, capacity); ++ else if (print_status) + printf(format, status); ++ else if (print_capacity) ++ printf(format, capacity); + else +- printf(format, status, capacity); ++ return EXIT_FAILURE; + printf("\n"); + fflush(stdout); + } +-- +2.42.0 + diff --git a/sutils/APKBUILD b/sutils/APKBUILD index 756bd61..01429ec 100644 --- a/sutils/APKBUILD +++ b/sutils/APKBUILD @@ -1,8 +1,9 @@ # Contributor: John Vogel <jvogel4@stny.rr.com> # Maintainer: John Vogel <jvogel4@stny.rr.com> pkgname=sutils -pkgver=0.2 -pkgrel=0 +pkgver=0.2_git20160411 +_commit=f35ea442858c362703d2fccb66a94b99f812f8a7 +pkgrel=1 pkgdesc="Small command-line utilities" url="https://github.com/baskerville/sutils/" arch="all" @@ -12,8 +13,13 @@ makedepends="alsa-lib-dev linux-headers" install="" subpackages="" options="!check" -source="https://github.com/baskerville/sutils/archive/$pkgver/sutils-$pkgver.tar.gz" -builddir="$srcdir/sutils-$pkgver" +source="https://github.com/baskerville/sutils/archive/$_commit/sutils-$pkgver.tar.gz + 0001-essid.c-change-put_status-to-return-int.patch + 0002-essid.c-take-some-care.patch + 0003-volume.c-take-some-care.patch + 0004-battery.c-be-more-careful-with-the-printf-format.patch + " +builddir="$srcdir/sutils-$_commit" build() { make @@ -24,5 +30,9 @@ package() { } sha512sums=" -35acb21216868ea9626e23b7b6faf0a6837d84a1ea6ca4b8ea57e9cb7b965e58d173b981f4bb0529f6eb08dd2fb2aa91a96623b5acaa49f55cd27c6f72ecd791 sutils-0.2.tar.gz +17d7297f7356912fc45877280d9bbe3378b9aa6c8a9b59cbfd527f88ed3675dcc61bc11b2f082c9fd016fe4e08426e33256990cc995de45faf6fd96b78c98558 sutils-0.2_git20160411.tar.gz +7736db9d01b4281d5f1b4d47df7216cfae27a05f52ee957f651f988cd62ce0a30223fc2de15c1df01562a08a593bf44dfd89786b470a05045b139b53622b16c4 0001-essid.c-change-put_status-to-return-int.patch +c94751bfc8c2ea5213e7c3ccb5eafe76856bb3bc83b82ca618028db17355b1e64af156add899a091f8171423fe1507023e679a6230959612046aecb9a5faa84d 0002-essid.c-take-some-care.patch +c06ce69fd3073e2d63f6b20a708d890454f36e18d04e693f98dc1a168c3fc11fbea801af41a323a5a6a74c1c395d47998df2350929c7a0c543dcfa752adc77b5 0003-volume.c-take-some-care.patch +8ea0bb304a58f813ab89ceed7df255f6e97773c6087c76e5bca58bc803fc41f3cdd58e1162307c949c261880ca32b85efdde1fc8c4b5d40914cc68d4f3bd8489 0004-battery.c-be-more-careful-with-the-printf-format.patch " |
