projects
/
project
/
uclient.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
uclient-utils: Handle memory allocation failure for url file name
[project/uclient.git]
/
uclient-fetch.c
diff --git
a/uclient-fetch.c
b/uclient-fetch.c
index
3c0c36b
..
38c9c53
100644
(file)
--- a/
uclient-fetch.c
+++ b/
uclient-fetch.c
@@
-50,7
+50,7
@@
static bool verify = true;
static bool proxy = true;
static bool default_certs = false;
static bool no_output;
static bool proxy = true;
static bool default_certs = false;
static bool no_output;
-static const char *output_file;
+static const char *o
pt_o
utput_file;
static int output_fd = -1;
static int error_ret;
static off_t out_offset;
static int output_fd = -1;
static int error_ret;
static off_t out_offset;
@@
-97,6
+97,7
@@
get_proxy_url(char *url)
static int open_output_file(const char *path, uint64_t resume_offset)
{
static int open_output_file(const char *path, uint64_t resume_offset)
{
+ const char *output_file = opt_output_file;
char *filename = NULL;
int flags;
int ret;
char *filename = NULL;
int flags;
int ret;
@@
-121,6
+122,11
@@
static int open_output_file(const char *path, uint64_t resume_offset)
}
} else {
filename = uclient_get_url_filename(path, "index.html");
}
} else {
filename = uclient_get_url_filename(path, "index.html");
+ if (!filename) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
output_file = filename;
}
output_file = filename;
}
@@
-150,6
+156,7
@@
done:
free:
free(filename);
free:
free(filename);
+out:
return ret;
}
return ret;
}
@@
-254,6
+261,7
@@
static void header_done_cb(struct uclient *cl)
static void read_data_cb(struct uclient *cl)
{
char buf[256];
static void read_data_cb(struct uclient *cl)
{
char buf[256];
+ ssize_t n;
int len;
if (!no_output && output_fd < 0)
int len;
if (!no_output && output_fd < 0)
@@
-261,12
+269,15
@@
static void read_data_cb(struct uclient *cl)
while (1) {
len = uclient_read(cl, buf, sizeof(buf));
while (1) {
len = uclient_read(cl, buf, sizeof(buf));
- if (
!len
)
+ if (
len <= 0
)
return;
out_bytes += len;
return;
out_bytes += len;
- if (!no_output)
- write(output_fd, buf, len);
+ if (!no_output) {
+ n = write(output_fd, buf, len);
+ if (n < 0)
+ return;
+ }
}
}
}
}
@@
-363,7
+374,7
@@
static void request_done(struct uclient *cl)
return;
}
return;
}
- if (output_fd >= 0 && !output_file) {
+ if (output_fd >= 0 && !o
pt_o
utput_file) {
close(output_fd);
output_fd = -1;
}
close(output_fd);
output_fd = -1;
}
@@
-489,7
+500,7
@@
static int no_ssl(const char *progname)
{
fprintf(stderr,
"%s: SSL support not available, please install one of the "
{
fprintf(stderr,
"%s: SSL support not available, please install one of the "
- "libustream-
ssl-* libraries as well as the ca-bundle and ",
+ "libustream-
.*[ssl|tls] packages as well as the ca-bundle and "
"ca-certificates packages.\n",
progname);
"ca-certificates packages.\n",
progname);
@@
-611,7
+622,7
@@
int main(int argc, char **argv)
user_agent = optarg;
break;
case 'O':
user_agent = optarg;
break;
case 'O':
- output_file = optarg;
+ o
pt_o
utput_file = optarg;
break;
case 'P':
if (chdir(optarg)) {
break;
case 'P':
if (chdir(optarg)) {
@@
-660,9
+671,11
@@
int main(int argc, char **argv)
uloop_init();
if (username) {
uloop_init();
if (username) {
- if (password)
- asprintf(&auth_str, "%s:%s", username, password);
- else
+ if (password) {
+ rc = asprintf(&auth_str, "%s:%s", username, password);
+ if (rc < 0)
+ return rc;
+ } else
auth_str = username;
}
auth_str = username;
}