Skip to content

Commit a172ec1

Browse files
committed
vcap/rtsp: fixed pointer passing
insteda to rtsp_state::rtsp_error_occurred, the error was printed to some place of stack (the address of `s` variable on stack plus offset of that attribute). \+ added magic value to ensure
1 parent 6498db9 commit a172ec1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/video_capture/rtsp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
#include <curl/curl.h>
8080

8181
#define KEEPALIVE_INTERVAL_S 5
82+
#define MAGIC to_fourcc('R', 'T', 'S', 'c')
8283
#define MOD_NAME "[rtsp] "
8384
#define VERSION_STR "V1.0"
8485

@@ -232,6 +233,7 @@ struct audio_rtsp_state {
232233
};
233234

234235
struct rtsp_state {
236+
uint32_t magic;
235237
CURL *curl;
236238
char uri[1024];
237239
rtps_types_t avType;
@@ -485,6 +487,7 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) {
485487

486488
int len = -1;
487489
char *save_ptr = NULL;
490+
s->magic = MAGIC;
488491
s->avType = none; //-1 none, 0 a&v, 1 v, 2 a
489492

490493
s->addr = "127.0.0.1";
@@ -663,6 +666,7 @@ static CURL *init_curl() {
663666
static size_t print_rtsp_header(char *buffer, size_t size, size_t nitems, void *userdata) {
664667
int aggregate_size = size * nitems;
665668
struct rtsp_state *s = (struct rtsp_state *) userdata;
669+
assert(s->magic == MAGIC);
666670
if (strncmp(buffer, "RTSP/1.0 ", MIN(strlen("RTSP/1.0 "), (size_t) aggregate_size)) == 0) {
667671
int code = atoi(buffer + strlen("RTSP/1.0 "));
668672
s->rtsp_error_occurred = code != 200;
@@ -711,7 +715,7 @@ init_rtsp(struct rtsp_state *s) {
711715
//my_curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, 1);
712716
my_curl_easy_setopt(s->curl, CURLOPT_VERBOSE, 0L, goto error);
713717
my_curl_easy_setopt(s->curl, CURLOPT_NOPROGRESS, 1L, goto error);
714-
my_curl_easy_setopt(s->curl, CURLOPT_HEADERDATA, &s, goto error);
718+
my_curl_easy_setopt(s->curl, CURLOPT_HEADERDATA, s, goto error);
715719
my_curl_easy_setopt(s->curl, CURLOPT_HEADERFUNCTION, print_rtsp_header, goto error);
716720
my_curl_easy_setopt(s->curl, CURLOPT_URL, s->uri, goto error);
717721

0 commit comments

Comments
 (0)