Environment: BUTT 1.47.0 on Windows x64, Icecast over TLS.
Steps to reproduce:
Actual: BUTT can log “Updated songname to” even when the server rejects the metadata update. The current implementation closes the TLS connection without reading the HTTP response and reports success unconditionally.
Expected: Report success only after a successful 2xx response; report transport errors, missing responses, and rejected status codes as failures.
Patch: Checks the send result, reads the HTTP status line before closing TLS, accepts only 2xx, and frees response buffers on either path.
Verification: Built a patched Windows x64 binary from BUTT 1.47.0. Focused checks accept 200 and reject 401 and malformed responses. The patched build also passed an end-to-end test against an Icecast development mount: the submitted title appeared in ICY StreamTitle metadata. The test source was disconnected afterward. No credentials or server configuration details are included.
Patch diff (src/icecast.cpp):
--- a/src/icecast.cpp
+++ b/src/icecast.cpp
@@ -491,10 +491,15 @@
int ret;
int web_socket;
char send_buf[1024];
+ char response_buf[512];
char auth[150];
char *song_buf;
char *mount;
char *b64_enc;
+ int send_len;
+ int response_len = 0;
+ int io_result;
+ int http_status = 0;
#ifdef HAVE_LIBSSL
tls_t web_tls;
#endif
@@ -577,24 +582,62 @@
free(b64_enc);
if (cfg.srv[cfg.selected_srv]->port == 80) {
- snprintf(send_buf + strlen(send_buf), sizeof(send_buf) - strlen(send_buf), "Host: %s\r\n\r\n", cfg.srv[cfg.selected_srv]->addr);
+ snprintf(send_buf + strlen(send_buf), sizeof(send_buf) - strlen(send_buf),
+ "Host: %s\r\nConnection: close\r\n\r\n", cfg.srv[cfg.selected_srv]->addr);
}
else {
- snprintf(send_buf + strlen(send_buf), sizeof(send_buf) - strlen(send_buf), "Host: %s:%d\r\n\r\n", cfg.srv[cfg.selected_srv]->addr,
+ snprintf(send_buf + strlen(send_buf), sizeof(send_buf) - strlen(send_buf),
+ "Host: %s:%d\r\nConnection: close\r\n\r\n", cfg.srv[cfg.selected_srv]->addr,
cfg.srv[cfg.selected_srv]->port);
}
+ send_len = (int)strlen(send_buf);
if (cfg.srv[cfg.selected_srv]->tls == 1) {
#ifdef HAVE_LIBSSL
- tls_send(&web_tls, send_buf, (int)strlen(send_buf), SEND_TIMEOUT);
+ io_result = tls_send(&web_tls, send_buf, send_len, SEND_TIMEOUT);
+ if (io_result == TLS_OK) {
+ while (response_len < (int)sizeof(response_buf) - 1 &&
+ memchr(response_buf, '\n', response_len) == NULL) {
+ io_result = tls_recv(&web_tls, response_buf + response_len,
+ (int)sizeof(response_buf) - response_len - 1,
+ 5 * RECV_TIMEOUT);
+ if (io_result <= 0) break;
+ response_len += io_result;
+ }
+ }
tls_close(&web_tls);
+#else
+ io_result = 0;
#endif
}
else {
- sock_send(web_socket, send_buf, (int)strlen(send_buf), SEND_TIMEOUT);
+ io_result = sock_send(web_socket, send_buf, send_len, SEND_TIMEOUT);
+ if (io_result == send_len) {
+ while (response_len < (int)sizeof(response_buf) - 1 &&
+ memchr(response_buf, '\n', response_len) == NULL) {
+ io_result = sock_recv(web_socket, response_buf + response_len,
+ (int)sizeof(response_buf) - response_len - 1,
+ 5 * RECV_TIMEOUT);
+ if (io_result <= 0) break;
+ response_len += io_result;
+ }
+ }
}
sock_close(web_socket);
+
+ response_buf[response_len] = '\0';
+ if (response_len == 0 || memchr(response_buf, '\n', response_len) == NULL ||
+ sscanf(response_buf, "HTTP/%*u.%*u %d", &http_status) != 1 ||
+ http_status < 200 || http_status >= 300) {
+ free(song_buf);
+ free(mount);
+ return IC_ABORT;
+ }
free(song_buf);
free(mount);
Hi, thank you for the patch. I will have a look at it.
Daniel