hstr: Add NULL check

for return value of `fopen("/proc/sys/kernel/hostname", "r")`.
This commit is contained in:
Tee KOBAYASHI 2022-12-04 03:07:24 +09:00 committed by xtkoba
parent 32ebd99680
commit 26c1239869
2 changed files with 19 additions and 0 deletions

View File

@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Shell history suggest box for bash and zsh"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=2.5
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://github.com/dvorka/hstr/archive/refs/tags/${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=7f5933fc07d55d09d5f7f9a6fbfdfc556d8a7d8575c3890ac1e672adabd2bec4
TERMUX_PKG_DEPENDS="ncurses, readline"

View File

@ -0,0 +1,18 @@
--- a/src/hstr_utils.c
+++ b/src/hstr_utils.c
@@ -154,6 +154,7 @@
char *b=buffer;
if(access(PROC_HOSTNAME, F_OK) != -1) {
FILE *file = fopen(PROC_HOSTNAME, "r");
+ if (file == NULL) goto fail;
b=fgets(buffer, bufferSize, file);
fclose(file);
if(b) {
@@ -161,6 +162,7 @@
return;
}
}
+fail:
strcpy(buffer, "localhost");
}