summaryrefslogtreecommitdiff
path: root/pkg/sshfs/patch/0005-Use-standard-C-functions.patch
blob: 5695152c25fa3f17f38c6762e094a1c60db0ffb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
From 088c5b6b0fa85da8fdb8490f8a587631967488ad Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Sun, 5 Jun 2016 17:42:29 -0700
Subject: [PATCH] Use standard C functions

---
 sshfs.c | 91 +++++++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 55 insertions(+), 36 deletions(-)

diff --git a/sshfs.c b/sshfs.c
index 4a01e4b..3f03640 100644
--- a/sshfs.c
+++ b/sshfs.c
@@ -654,25 +654,25 @@ static inline void buf_add_path(struct buffer *buf, const char *path)
 	if (sshfs.base_path[0]) {
 		if (path[1]) {
 			if (sshfs.base_path[strlen(sshfs.base_path)-1] != '/') {
-				realpath = g_strdup_printf("%s/%s",
-							   sshfs.base_path,
-							   path + 1);
+				if (asprintf(&realpath, "%s/%s", sshfs.base_path, path + 1) < 0)
+					abort();
 			} else {
-				realpath = g_strdup_printf("%s%s",
-							   sshfs.base_path,
-							   path + 1);
+				if (asprintf(&realpath, "%s%s", sshfs.base_path, path + 1) < 0)
+					abort();
 			}
 		} else {
-			realpath = g_strdup(sshfs.base_path);
+			realpath = strdup(sshfs.base_path);
 		}
 	} else {
 		if (path[1])
-			realpath = g_strdup(path + 1);
+			realpath = strdup(path + 1);
 		else
-			realpath = g_strdup(".");
+			realpath = strdup(".");
 	}
+	if (!realpath)
+		abort();
 	buf_add_string(buf, realpath);
-	g_free(realpath);
+	free(realpath);
 }
 
 static int buf_check_get(struct buffer *buf, size_t len)
@@ -1257,7 +1257,7 @@ static void request_free(struct request *req)
 {
 	buf_free(&req->reply);
 	sem_destroy(&req->ready);
-	g_free(req);
+	free(req);
 }
 
 static int request_table_insert(struct request_table *reqtab, struct request *req)
@@ -1305,9 +1305,9 @@ static void chunk_free(struct read_chunk *chunk)
 		rreq = list_entry(chunk->reqs.prev, struct read_req, list);
 		list_del(&rreq->list);
 		buf_free(&rreq->data);
-		g_free(rreq);
+		free(rreq);
 	}
-	g_free(chunk);
+	free(chunk);
 }
 
 static void chunk_put(struct read_chunk *chunk)
@@ -1862,8 +1862,10 @@ static int sftp_request_send(uint8_t type, struct iovec *iov, size_t count,
                              struct request **reqp)
 {
 	int err;
-	struct request *req = g_new0(struct request, 1);
+	struct request *req = calloc(1, sizeof(struct request));
 
+	if (!req)
+		return -ENOMEM;
 	req->want_reply = want_reply;
 	req->end_func = end_func;
 	req->data = data;
@@ -2579,8 +2581,10 @@ static int sshfs_open_common(const char *path, mode_t mode,
 
 	if (fi->flags & O_APPEND)
 		pflags |= SSH_FXF_APPEND;
-	
-	sf = g_new0(struct sshfs_file, 1);
+
+	sf = calloc(1, sizeof(struct sshfs_file));
+	if (!sf)
+		return -ENOMEM;
 	list_init(&sf->write_reqs);
 	pthread_cond_init(&sf->write_finished, NULL);
 	/* Assume random read after open */
@@ -2624,7 +2628,7 @@ static int sshfs_open_common(const char *path, mode_t mode,
 	} else {
 		if (sshfs.dir_cache)
 			cache_invalidate(path);
-		g_free(sf);
+		free(sf);
 	}
 	buf_free(&buf);
 	return err;
@@ -2691,7 +2695,7 @@ static void sshfs_file_put(struct sshfs_file *sf)
 {
 	sf->refs--;
 	if (!sf->refs)
-		g_free(sf);
+		free(sf);
 }
 
 static void sshfs_file_get(struct sshfs_file *sf)
@@ -2761,9 +2765,11 @@ static void sshfs_read_begin(struct request *req)
 static struct read_chunk *sshfs_send_read(struct sshfs_file *sf, size_t size,
 					  off_t offset)
 {
-	struct read_chunk *chunk = g_new0(struct read_chunk, 1);
+	struct read_chunk *chunk = calloc(1, sizeof(struct read_chunk));
 	struct buffer *handle = &sf->handle;
 
+	if (!chunk)
+		abort();
 	pthread_cond_init(&chunk->sio.finished, NULL);
 	list_init(&chunk->reqs);
 	chunk->size = size;
@@ -2777,7 +2783,9 @@ static struct read_chunk *sshfs_send_read(struct sshfs_file *sf, size_t size,
 		struct read_req *rreq;
 		size_t bsize = size < sshfs.max_read ? size : sshfs.max_read;
 
-		rreq = g_new0(struct read_req, 1);
+		rreq = calloc(1, sizeof(struct read_req));
+		if (!rreq)
+			abort();
 		rreq->sio = &chunk->sio;
 		rreq->size = bsize;
 		buf_init(&rreq->data, 0);
@@ -2848,7 +2856,7 @@ static int wait_chunk(struct read_chunk *chunk, char *buf, size_t size)
 			size -= rreq->res;
 			list_del(&rreq->list);
 			buf_free(&rreq->data);
-			g_free(rreq);
+			free(rreq);
 		}
 	}
 
@@ -3468,9 +3476,10 @@ static int sshfs_opt_proc(void *data, const char *arg, int key,
 	switch (key) {
 	case FUSE_OPT_KEY_OPT:
 		if (is_ssh_opt(arg)) {
-			tmp = g_strdup_printf("-o%s", arg);
+			if (asprintf(&tmp, "-o%s", arg) < 0)
+				abort();
 			ssh_add_arg(tmp);
-			g_free(tmp);
+			free(tmp);
 			return 0;
 		}
 		/* Pass through */
@@ -3495,9 +3504,10 @@ static int sshfs_opt_proc(void *data, const char *arg, int key,
 
 
 	case KEY_PORT:
-		tmp = g_strdup_printf("-oPort=%s", arg + 2);
+		if (asprintf(&tmp, "-oPort=%s", arg + 2) < 0)
+			abort();
 		ssh_add_arg(tmp);
-		g_free(tmp);
+		free(tmp);
 		return 0;
 
 	case KEY_COMPRESS:
@@ -3505,9 +3515,10 @@ static int sshfs_opt_proc(void *data, const char *arg, int key,
 		return 0;
 
 	case KEY_CONFIGFILE:
-		tmp = g_strdup_printf("-F%s", arg + 2);
+		if (asprintf(&tmp, "-F%s", arg + 2) < 0)
+			abort();
 		ssh_add_arg(tmp);
-		g_free(tmp);
+		free(tmp);
 		return 0;
 
 	default:
@@ -3663,17 +3674,19 @@ static char *find_base_path(void)
 
 static char *fsname_escape_commas(char *fsnameold)
 {
-	char *fsname = g_malloc(strlen(fsnameold) * 2 + 1);
+	char *fsname = malloc(strlen(fsnameold) * 2 + 1);
 	char *d = fsname;
 	char *s;
 
+	if (!fsname)
+		abort();
 	for (s = fsnameold; *s; s++) {
 		if (*s == '\\' || *s == ',')
 			*d++ = '\\';
 		*d++ = *s;
 	}
 	*d = '\0';
-	g_free(fsnameold);
+	free(fsnameold);
 
 	return fsname;
 }
@@ -4008,15 +4021,20 @@ int main(int argc, char *argv[])
 	else
 		sshfs.max_outstanding_len = ~0;
 
-	fsname = g_strdup(sshfs.host);
-	sshfs.base_path = g_strdup(find_base_path());
+	fsname = strdup(sshfs.host);
+	if (!fsname)
+		abort();
+	sshfs.base_path = strdup(find_base_path());
+	if (!sshfs.base_path)
+		abort();
 
 	if (sshfs.ssh_command)
 		set_ssh_command();
 
-	tmp = g_strdup_printf("-%i", sshfs.ssh_ver);
+	if (asprintf(&tmp, "-%i", sshfs.ssh_ver) < 0)
+		abort();
 	ssh_add_arg(tmp);
-	g_free(tmp);
+	free(tmp);
 	ssh_add_arg(sshfs.host);
 	if (sshfs.sftp_server)
 		sftp_server = sshfs.sftp_server;
@@ -4043,10 +4061,11 @@ int main(int argc, char *argv[])
 		sshfs.max_write = 65536;
 
         fsname = fsname_escape_commas(fsname);
-	tmp = g_strdup_printf("-osubtype=sshfs,fsname=%s", fsname);
+	if (asprintf(&tmp, "-osubtype=sshfs,fsname=%s", fsname) < 0)
+		abort();
 	fuse_opt_insert_arg(&args, 1, tmp);
-	g_free(tmp);
-	g_free(fsname);
+	free(tmp);
+	free(fsname);
 
 	if(sshfs.dir_cache)
 		sshfs.op = cache_wrap(&sshfs_oper);
-- 
2.14.1