cgmnlm

colorful gemini line mode browser
git clone https://git.clttr.info/cgmnlm.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit fbcc28fad8870439dcd8a038f31dcab05f3e3bc9
parent c88e697b3309784e67a7b0d44423494fbda01774
Author: René Wagner <rwa@clttr.info>
Date:   Wed,  3 Nov 2021 16:34:38 +0100

make download_resp() match upstream

Diffstat:
Msrc/util.c | 32++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/util.c b/src/util.c @@ -66,24 +66,40 @@ download_resp(FILE *out, struct gemini_response resp, const char *path, char *url) { char path_buf[PATH_MAX]; + int n = 0; assert(path); switch (path[0]) { case '\0': - strncpy(path_buf, "./", 3); + strcpy(path_buf, "./"); break; - case '~':; - int n = snprintf(path_buf, PATH_MAX, "%s/%s", getenv("HOME"), &path[1]); - assert((size_t)n < PATH_MAX); + case '~': + n = snprintf(path_buf, PATH_MAX, "%s/%s", getenv("HOME"), &path[1]); + if (n > PATH_MAX) { + fprintf(stderr, + "Path %s exceeds limit of %d bytes and has been truncated\n", + path_buf, PATH_MAX); + return 1; + } break; default: - strncpy(path_buf, path, PATH_MAX); + if (strlen(path) > PATH_MAX) { + fprintf(stderr, "Path %s exceeds limit of %d bytes\n", + path, PATH_MAX); + return 1; + } + strcpy(path_buf, path); } char path_res[PATH_MAX]; if (path_buf[strlen(path_buf)-1] == '/') { - int n = snprintf(path_res, PATH_MAX, "%s%s", path_buf, basename(url)); - assert((size_t)n < PATH_MAX); + n = snprintf(path_res, PATH_MAX, "%s%s", path_buf, basename(url)); + if (n > PATH_MAX) { + fprintf(stderr, + "Path %s exceeds limit of %d bytes and has been truncated\n", + path_res, PATH_MAX); + return 1; + } } else { - strncpy(path_res, path_buf, PATH_MAX); + strcpy(path_res, path_buf); } FILE *f = fopen(path_res, "w"); if (f == NULL) {