Skip to content

Commit 9489fa5

Browse files
rveerama1jukkar
authored andcommitted
net: http: Fix http_prepare_and_send
net_pkt_append() has been changed. If payload reached max value of 'data_len' in net packet, net_pkt_append will not append. So the caller has to create new packet and append remaining payload. Signed-off-by: Ravi kumar Veeramally <[email protected]>
1 parent d6ca4de commit 9489fa5

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

subsys/net/lib/http/http.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,37 @@ int http_prepare_and_send(struct http_ctx *ctx,
139139

140140
ret = net_pkt_append(ctx->pending, payload_len, payload,
141141
ctx->timeout);
142+
if (!ret || ret > payload_len) {
143+
ret = -EINVAL;
144+
goto error;
145+
}
142146

143147
added = ret;
144148

145-
if (added < payload_len) {
146-
/* Not all data could be added, send what we have now
147-
* and allocate new stuff to be sent.
148-
*/
149-
ret = http_send_flush(ctx, user_send_data);
150-
if (ret < 0) {
151-
return ret;
152-
}
153-
154-
payload_len -= added;
149+
payload_len -= added;
150+
if (payload_len) {
155151
payload += added;
156152
}
157-
} while (added < payload_len);
153+
154+
/* Not all data could be added, send what we have now
155+
* and allocate new stuff to be sent.
156+
*/
157+
ret = http_send_flush(ctx, user_send_data);
158+
if (ret < 0) {
159+
goto error;
160+
}
161+
162+
} while (payload_len);
158163

159164
return 0;
165+
166+
error:
167+
if (ctx->pending) {
168+
net_pkt_unref(ctx->pending);
169+
ctx->pending = NULL;
170+
}
171+
172+
return ret;
160173
}
161174

162175
int http_send_flush(struct http_ctx *ctx, void *user_send_data)

0 commit comments

Comments
 (0)