Commit dc4a3e3644b5c1669880b49f83b243d8783d4df5

humphreyj 2018-09-07T01:59:08

Add missing attachment argument (-a) to mailx example program. Add a check to prevent caller from using a NULL file path or file name when sending an attachment.

diff --git a/src/mailx.c b/src/mailx.c
index 4c20a80..4c6e788 100644
--- a/src/mailx.c
+++ b/src/mailx.c
@@ -273,6 +273,10 @@ mailx_append_attachment(struct mailx *const mailx,
   struct mailx_attachment *new_attachment;
   size_t new_attachment_list_sz;
 
+  if(filename == NULL || path == NULL){
+    errx(1, "must provide attachment with valid name:path");
+  }
+
   new_attachment_list_sz = (mailx->num_attachment + 1) *
                            sizeof(*mailx->attachment_list);
   if((mailx->attachment_list = realloc(mailx->attachment_list,
@@ -498,7 +502,7 @@ int main(int argc, char *argv[]){
 
   mailx_init_default_values(&mailx);
 
-  while((rc = getopt(argc, argv, "s:S:")) != -1){
+  while((rc = getopt(argc, argv, "a:s:S:")) != -1){
     switch(rc){
     case 'a':
       mailx_append_attachment_arg(&mailx, optarg);