Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #12 from pozdnychev/master

Minor bugfixes after a quick review
  • Loading branch information...
commit 69ab42a97e450382b9e84eb2c6cc62ca23ba5cf4 2 parents 9653a2b + e4943b8
@benlemasurier authored
Showing with 91 additions and 21 deletions.
  1. +51 −15 src/curl.c
  2. +11 −2 src/s3.c
  3. +29 −4 src/stormfs.c
View
66 src/curl.c
@@ -562,12 +562,17 @@ get_etag_from_xml(char *xml)
end_p = strstr(xml, end_marker);
tmp = g_strndup(start_p, end_p - start_p);
+ if (! tmp) {
+ perror("g_strndup");
+ exit(EXIT_FAILURE);
+ }
+
if(asprintf(&etag, "\"%s\"", tmp) == -1) {
fprintf(stderr, "unable to allocate memory\n");
exit(EXIT_FAILURE);
}
- free(tmp);
+ g_free(tmp);
return etag;
}
@@ -818,16 +823,17 @@ static int
sign_request(const char *method,
struct curl_slist **headers, const char *path)
{
- char *signature;
- char *to_sign;
- char *date_header;
- char *amz_headers;
- char *content_type;
- char *authorization;
+ char *signature = NULL;
+ char *to_sign = NULL;
+ char *date_header = NULL;
+ char *amz_headers = NULL;
+ char *content_type = NULL;
+ char *authorization = NULL;
struct curl_slist *next = NULL;
struct curl_slist *header = NULL;
char *date = rfc2822_timestamp();
char *resource = get_resource(path);
+ char *dummy = NULL;
amz_headers = g_malloc0(sizeof(char));
content_type = g_malloc0(sizeof(char) * 2);
@@ -836,14 +842,27 @@ sign_request(const char *method,
next = header->next;
if(strstr(header->data, "x-amz") != NULL) {
- amz_headers = realloc(amz_headers, sizeof(char) * strlen(amz_headers) +
+ dummy = realloc(amz_headers, sizeof(char) * strlen(amz_headers) +
strlen(header->data) + 2);
+ if (! dummy) {
+ perror("realloc");
+ exit(EXIT_FAILURE);
+ }
+
+ amz_headers = dummy;
amz_headers = strncat(amz_headers, header->data, strlen(header->data));
amz_headers = strncat(amz_headers, "\n", 1);
} else if(strstr(header->data, "Content-Type") != NULL) {
char *tmp = strstr(header->data, ":") + 1;
- content_type = realloc(content_type, sizeof(char) * strlen(content_type) +
+
+ dummy = realloc(content_type, sizeof(char) * strlen(content_type) +
strlen(content_type) + strlen(tmp) + 2);
+ if (! dummy) {
+ perror("realloc");
+ exit(EXIT_FAILURE);
+ }
+
+ content_type = dummy;
content_type = strncat(content_type, tmp, strlen(tmp));
}
@@ -1432,10 +1451,13 @@ stormfs_curl_head_multi(const char *path, GList *files)
int
stormfs_curl_list_bucket(const char *path, char **xml)
{
- int result;
- char *marker = g_strdup("");
+ int result = -1;
+ char *marker = strdup("");
bool truncated = TRUE;
+ if (! marker)
+ return result;
+
while(truncated) {
char *url = get_list_bucket_url(path, marker);
CURL *c = get_pooled_handle(url);
@@ -1597,10 +1619,23 @@ complete_multipart_xml(GList *parts)
{
int result;
GList *head = NULL, *next = NULL;
- char *xml = strdup("<CompleteMultipartUpload>\n");
+ char *tmp = NULL;
+ char *xml = NULL;
- xml = realloc(xml, sizeof(char) *
- strlen(xml) + (g_list_length(parts) * 150));
+ xml = strdup("<CompleteMultipartUpload>\n");
+ if (! xml) {
+ perror("strdup");
+ exit(EXIT_FAILURE);
+ }
+
+ tmp = realloc(xml, sizeof(char) *
+ strlen(xml) + (g_list_length(parts) * 150));
+ if (! tmp) {
+ perror("realloc");
+ exit(EXIT_FAILURE);
+ }
+
+ xml = tmp;
head = g_list_first(parts);
while(head != NULL) {
@@ -1779,7 +1814,7 @@ create_file_parts(const char *path, char *upload_id, int fd)
int part_num = 1;
bytes_remaining = st.st_size;
while(bytes_remaining > 0) {
- char *buf;
+ char *buf = NULL;
size_t nbytes;
FILE *tmp_f;
FILE_PART *fp = create_part(part_num, upload_id);
@@ -1796,6 +1831,7 @@ create_file_parts(const char *path, char *upload_id, int fd)
if((tmp_f = fdopen(fp->fd, "wb")) == NULL) {
perror("fdopen");
+ free(buf);
return NULL;
}
View
13 src/s3.c
@@ -64,9 +64,14 @@ xml_to_files(const char *path, char *xml)
char *end_p = strstr(start_p, "</Key>");
name = g_strndup(start_p, end_p - start_p);
+ if (! name) {
+ perror("g_strndup");
+ return NULL;
+ }
+
fullpath = get_path(path, name);
files = add_file_to_list(files, fullpath, NULL);
- free(name);
+ g_free(name);
free(fullpath);
if((start_p = strstr(end_p, "<Key>")) != NULL)
@@ -319,6 +324,10 @@ s3_rename_directory(const char *from, const char *to, struct stat *st)
struct stat stbuf;
tmp = g_strndup(start_p, end_p - start_p);
+ if (! tmp) {
+ return -ENOMEM;
+ }
+
name = basename(tmp);
file_from = get_path(from, name);
file_to = get_path(to, name);
@@ -334,7 +343,7 @@ s3_rename_directory(const char *from, const char *to, struct stat *st)
return result;
}
- free(tmp);
+ g_free(tmp);
free(file_to);
free(file_from);
View
33 src/stormfs.c
@@ -89,14 +89,21 @@ valid_path(const char *path)
{
char *p = NULL;
char *tmp = strdup(path);
+ if (! tmp)
+ return -ENOMEM;
- if(strlen(path) > PATH_MAX)
+
+ if(strlen(path) > PATH_MAX) {
+ free(tmp);
return -ENAMETOOLONG;
+ }
p = strtok(tmp, "/");
while(p != NULL) {
- if(strlen(p) > NAME_MAX)
+ if(strlen(p) > NAME_MAX) {
+ free(tmp);
return -ENAMETOOLONG;
+ }
p = strtok(NULL, "/");
}
@@ -150,6 +157,8 @@ cache_mkpath(const char *path)
tmp = g_malloc0(sizeof(char) *
strlen(stormfs.cache_path) + strlen(dir) + 1);
+ if (! tmp)
+ return -ENOMEM;
p = strtok(dir, "/");
while(p != NULL) {
@@ -303,8 +312,13 @@ cache_invalidate_dir(const char *path)
g_hash_table_remove(cache.files, "/");
else {
char *parent = g_strndup(path, s - path);
+ if (! parent) {
+ perror("g_strndup");
+ return;
+ }
+
cache_invalidate(parent);
- free(parent);
+ g_free(parent);
}
}
}
@@ -523,7 +537,13 @@ get_mime_type(const char *filename)
{
char *type = NULL;
char *p = NULL, *ext = NULL;
- char *name = strdup(filename);
+ char *name = NULL;
+
+ name = strdup(filename);
+ if (! name) {
+ perror("strdup");
+ return NULL;
+ }
p = strtok(name, ".");
while(p != NULL) {
@@ -536,6 +556,7 @@ get_mime_type(const char *filename)
if(strcmp(filename, ext) == 0) {
free(name);
+ free(ext);
return NULL;
}
@@ -1292,6 +1313,10 @@ parse_config(const char *path)
char *p = NULL;
char buf[BUFSIZ + 1];
struct stat *st = g_malloc0(sizeof(struct stat));
+ if (! st) {
+ perror("g_malloc0");
+ exit(EXIT_FAILURE);
+ }
if(stat(path, st) == -1) {
fprintf(stderr, "%s: missing configuration file %s\n",
Please sign in to comment.
Something went wrong with that request. Please try again.