Browse Source

Add checks for functions that may fail

Georgi Chorbadzhiyski 7 years ago
parent
commit
6e34110ff1
2 changed files with 13 additions and 7 deletions
  1. 5
    5
      notify.c
  2. 8
    2
      process.c

+ 5
- 5
notify.c View File

54
 		int e = 0;
54
 		int e = 0;
55
 		unsigned int i, r;
55
 		unsigned int i, r;
56
 		char **env = calloc(32, sizeof(char *));
56
 		char **env = calloc(32, sizeof(char *));
57
-		asprintf(&env[e++], "_TS=%ld"			, time(NULL));
58
-		asprintf(&env[e++], "_IDENT=%s"			, shared->ident);
59
-		asprintf(&env[e++], "_MESSAGE_ID=%s"	, shared->msg_id);
60
-		asprintf(&env[e++], "_MESSAGE_TEXT=%s"	, shared->text);
57
+		if (asprintf(&env[e++], "_TS=%ld"			, time(NULL)) < 0) exit(EXIT_FAILURE);
58
+		if (asprintf(&env[e++], "_IDENT=%s"			, shared->ident) < 0) exit(EXIT_FAILURE);
59
+		if (asprintf(&env[e++], "_MESSAGE_ID=%s"	, shared->msg_id) < 0) exit(EXIT_FAILURE);
60
+		if (asprintf(&env[e++], "_MESSAGE_TEXT=%s"	, shared->text) < 0) exit(EXIT_FAILURE);
61
 		r = strlen(shared->msg_id);
61
 		r = strlen(shared->msg_id);
62
 		for (i=0; i<r; i++) {
62
 		for (i=0; i<r; i++) {
63
 			if (isalpha(shared->msg_id[i]))
63
 			if (isalpha(shared->msg_id[i]))
65
 			if (shared->msg_id[i] == '_')
65
 			if (shared->msg_id[i] == '_')
66
 				shared->msg_id[i] = ' ';
66
 				shared->msg_id[i] = ' ';
67
 		}
67
 		}
68
-		asprintf(&env[e++], "_MESSAGE_MSG=%s"	, shared->msg_id);
68
+		if (asprintf(&env[e++], "_MESSAGE_MSG=%s"	, shared->msg_id) < 0) exit(EXIT_FAILURE);
69
 		execve(args[0], args, env);
69
 		execve(args[0], args, env);
70
 		// We reach here only if there is an error.
70
 		// We reach here only if there is an error.
71
 		fprintf(stderr, "execve('%s') failed: %s!\n", args[0], strerror(errno));
71
 		fprintf(stderr, "execve('%s') failed: %s!\n", args[0], strerror(errno));

+ 8
- 2
process.c View File

258
 	if (ts->no_output_on_error && !ts->camd.key->is_valid_cw)
258
 	if (ts->no_output_on_error && !ts->camd.key->is_valid_cw)
259
 		return;
259
 		return;
260
 	if (!ts->rtp_output) {
260
 	if (!ts->rtp_output) {
261
-		write(ts->output.fd, data, data_size);
261
+		if (write(ts->output.fd, data, data_size) < 0) {
262
+			perror("write(output_fd)");
263
+			return;
264
+		}
262
 	} else {
265
 	} else {
263
 		struct iovec iov[2];
266
 		struct iovec iov[2];
264
 		uint8_t rtp_header[12];
267
 		uint8_t rtp_header[12];
286
 		iov[1].iov_base = data;
289
 		iov[1].iov_base = data;
287
 		iov[1].iov_len  = data_size;
290
 		iov[1].iov_len  = data_size;
288
 
291
 
289
-		writev(ts->output.fd, iov, 2);
292
+		if (writev(ts->output.fd, iov, 2) < 0) {
293
+			perror("writev(output_fd)");
294
+			return;
295
+		}
290
 	}
296
 	}
291
 }
297
 }
292
 
298
 

Loading…
Cancel
Save