Changeset 1c6c4d3


Ignore:
Timestamp:
Jun 30, 2002, 4:58:09 PM (22 years ago)
Author:
Erik Nygren <nygren@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
507d5aa
Parents:
262422c
Message:
	Added owl_sprintf which returns the formatted string, or NULL.
	        The caller must free this string.
		This will allocate enough memory and thus
		avoid potential some buffer overrun situations.
	Started fixing some potential buffer overrun situations.
	Simple implementation of 'zwrite -m' (doesn't yet log an outgoing
	        message as having been sent.)
	The "Not logged in or subscribing to messages" error
	        now includes the name of the recipient.
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rb68f9cd r1c6c4d3  
    1212        Added "reply zaway" which sends a zaway response to the current msg.
    1313        Added "edit:delete-prev-word" command and bound M-BACKSPACE to it.
     14        Added owl_sprintf which returns the formatted string, or NULL.
     15                The caller must free this string.
     16                This will allocate enough memory and thus
     17                avoid potential some buffer overrun situations.
     18        Started fixing some potential buffer overrun situations.
     19        Simple implementation of 'zwrite -m' (doesn't yet log an outgoing
     20                message as having been sent.)
     21        The "Not logged in or subscribing to messages" error
     22                now includes the name of the recipient.
    1423               
    15241.2.1-pre-1
  • commands.c

    rb68f9cd r1c6c4d3  
    8181  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
    8282              "send a zephyr",
    83               "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] ",
     83              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] [-m <message...>]",
    8484              "Zwrite send a zephyr to the one or more users specified.\n\n"
    8585              "The following options are available:\n\n"
     86              "-m    Specifies a message to send without prompting.\n"
     87              "      Note that this does not yet log an outgoing message.\n"
     88              "      This must be the last argument.\n\n"
    8689              "-n    Do not send a ping message.\n\n"
    8790              "-C    If the message is sent to more than one user include a\n"
     
    11111114
    11121115char *owl_command_zwrite(int argc, char **argv, char *buff) {
    1113   char *tmpbuff;
     1116  char *tmpbuff, *pos, *cmd, *msg;
     1117
     1118  /* check for a zwrite -m */
     1119  for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
     1120    if (!strncmp(pos, "-m ", 3)) {
     1121      cmd = owl_strdup(buff);
     1122      msg = cmd+(pos-buff);
     1123      *msg = '\0';
     1124      msg += 3;
     1125      owl_zwrite_create_and_send_from_line(cmd, msg);
     1126      owl_free(cmd);
     1127      return NULL;
     1128    }
     1129  }
     1130
    11141131  if (argc < 2) {
    11151132    owl_function_makemsg("Not enough arguments to the zwrite command.");
  • functions.c

    rd36f2cb r1c6c4d3  
    155155  /* display the message as an admin message in the receive window */
    156156  if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
    157     tmpbuff=owl_malloc(strlen(owl_editwin_get_text(owl_global_get_typwin(&g)))+1024);
    158157    owl_zwrite_get_recipstr(&z, buff);
    159     sprintf(tmpbuff, "Message sent to %s", buff);
     158    tmpbuff = owl_sprintf("Message sent to %s", buff);
    160159    owl_function_adminmsg_outgoing(tmpbuff, owl_editwin_get_text(owl_global_get_typwin(&g)), line);
    161160    owl_free(tmpbuff);
     
    11621161  }
    11631162
    1164   buff=malloc(num*200);
     1163  buff=owl_malloc(num*200);
    11651164  strcpy(buff, "");
    11661165  for (i=0; i<num; i++) {
     
    11731172
    11741173  owl_function_popless_text(buff);
    1175   free(buff);
     1174  owl_free(buff);
    11761175  ZFlushSubscriptions();
    11771176}
     
    12661265  owl_view *v;
    12671266  owl_filter *f;
    1268   char buff[LINE];
    12691267
    12701268  /* get the trash filter */
     
    12871285  }
    12881286  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    1289   sprintf(buff, "%i messages marked for deletion", count);
    1290   owl_function_makemsg(buff);
     1287  owl_function_makemsg("%i messages marked for deletion", count);
    12911288  owl_global_set_needrefresh(&g);
    12921289}
  • owl.c

    r1aee7d9 r1c6c4d3  
    273273      /* this is an unsupported feature */
    274274      if (owl_global_is_burningears(&g) && owl_message_is_burningears(m)) {
    275         char buff[LINE];
    276         sprintf(buff, "@i(Burning ears message on class %s)", owl_message_get_class(m));
     275        char *buff;
     276        buff = owl_sprintf("@i(Burning ears message on class %s)", owl_message_get_class(m));
    277277        /* owl_function_makemsg(buff); */
    278278        owl_function_adminmsg(buff, "");
     279        owl_free(buff);
    279280        owl_function_beep();
    280281      }
  • util.c

    r1aee7d9 r1c6c4d3  
    2828    strcpy(buff, " (-/-) ");
    2929  } else {
    30     sprintf(buff, " (%i/%i/%i) ", owl_global_get_curmsg(&g)+1,
     30    snprintf(buff, 1024, " (%i/%i/%i) ", owl_global_get_curmsg(&g)+1,
    3131            owl_view_get_size(v),
    3232            owl_messagelist_get_size(ml));
     
    6262    getyx(sepwin, y, x);
    6363    wmove(sepwin, y, x+2);
    64     sprintf(buff, " right: %i ", owl_global_get_rightshift(&g));
     64    snprintf(buff, 1024, " right: %i ", owl_global_get_rightshift(&g));
    6565    waddstr(sepwin, buff);
    6666  }
     
    316316}
    317317
     318/* allocates memory and returns the string or null.
     319 * caller must free the string.
     320 * from Linux sprintf man page.
     321 */
     322char *owl_sprintf(const char *fmt, ...) {
     323  int n, size = 100;
     324  char *p;
     325  va_list ap;
     326  if ((p = owl_malloc (size)) == NULL)
     327    return NULL;
     328  while (1) {
     329    /* Try to print in the allocated space. */
     330    va_start(ap, fmt);
     331    n = vsnprintf (p, size, fmt, ap);
     332    va_end(ap);
     333    /* If that worked, return the string. */
     334    if (n > -1 && n < size)
     335      return p;
     336    /* Else try again with more space. */
     337    if (n > -1)    /* glibc 2.1 */
     338      size = n+1; /* precisely what is needed */
     339    else           /* glibc 2.0 */
     340      size *= 2;  /* twice the old size */
     341    if ((p = owl_realloc (p, size)) == NULL)
     342      return NULL;
     343  }
     344}
     345
    318346char *pretty_sender(char *in) {
    319347  char *out, *ptr;
     
    331359
    332360char *long_sender(char *in) {
    333   char *out, *ptr;
     361  char *ptr;
    334362
    335363  /* the caller must free the return */
    336   out=owl_malloc(strlen(in)+100);
    337   strcpy(out, in);
    338   ptr=strchr(out, '@');
    339   if (ptr) return(out);
    340   sprintf(out, "%s@%s", out, ZGetRealm());
    341   return(out);
     364  if (NULL != (ptr=strchr(in, '@'))) {
     365    return owl_strdup(in);
     366  } else {
     367    return owl_sprintf("%s@%s", in, ZGetRealm());
     368  }
    342369}
    343370                 
  • zephyr.c

    r1aee7d9 r1c6c4d3  
    111111        subs[count].zsub_classinst=owl_strdup(buffer);
    112112      } else {
    113         subs[count].zsub_classinst=owl_malloc(1024);
    114         sprintf(subs[count].zsub_classinst, "%s@%s", buffer, ZGetRealm());
     113        subs[count].zsub_classinst=owl_sprintf("%s@%s", buffer, ZGetRealm());
    115114      }
    116115
     
    346345
    347346void owl_zephyr_handle_ack(ZNotice_t *retnotice) {
    348   char buff[LINE];
    349347  char *tmp;
    350348 
     
    362360               !strcasecmp(retnotice->z_class_inst, "personal")) {
    363361      tmp=pretty_sender(retnotice->z_recipient);
    364       sprintf(buff, "Message sent to %s.", tmp);
     362      owl_function_makemsg("Message sent to %s.", tmp);
    365363      free(tmp);
    366364    } else {
    367       sprintf(buff, "Message sent to -c %s -i %s\n", retnotice->z_class, retnotice->z_class_inst);
    368     }
    369     owl_function_makemsg(buff);
     365      owl_function_makemsg("Message sent to -c %s -i %s\n", retnotice->z_class, retnotice->z_class_inst);
     366    }
    370367  } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) {
    371368    if (strcasecmp(retnotice->z_class, "message")) {
    372       sprintf(buff, "Not logged in or not subscribing to class %s, instance %s",
     369      owl_function_makemsg("Not logged in or not subscribing to class %s, instance %s",
    373370              retnotice->z_class, retnotice->z_class_inst);
    374       owl_function_makemsg(buff);
    375371    } else {
    376       owl_function_makemsg("Not logged in or subscribing to messages.");
    377     }
    378   } else {
    379     char buff[1024];
    380     sprintf(buff, "Internal error on ack (%s)", retnotice->z_message);
    381     owl_function_makemsg(buff);
     372      tmp = pretty_sender(retnotice->z_recipient);
     373      owl_function_makemsg("%s: Not logged in or subscribing to messages.",
     374                           tmp);
     375      owl_free(tmp);
     376    }
     377  } else {
     378    owl_function_makemsg("Internal error on ack (%s)", retnotice->z_message);
    382379  }
    383380}
     
    412409
    413410  /* display the message as an admin message in the receive window */
    414   tmpbuff=owl_malloc(strlen(owl_global_get_zaway_msg(&g))+LINE);
    415   sprintf(tmpbuff, "Message sent to %s", owl_message_get_sender(m));
     411  tmpbuff = owl_sprintf("Message sent to %s", owl_message_get_sender(m));
    416412  owl_function_adminmsg(tmpbuff, owl_global_get_zaway_msg(&g));
    417413  owl_free(tmpbuff);
  • zwrite.c

    r1aee7d9 r1c6c4d3  
    33
    44static const char fileIdent[] = "$Id$";
     5
     6int owl_zwrite_create_and_send_from_line(char *cmd, char *msg) {
     7  owl_zwrite z;
     8  int rv;
     9  rv = owl_zwrite_create_from_line(&z, cmd);
     10  if (rv) return(rv);
     11  owl_zwrite_send_message(&z, msg);
     12  owl_zwrite_free(&z);
     13  return(0);
     14}
    515
    616int owl_zwrite_create_from_line(owl_zwrite *z, char *line) {
Note: See TracChangeset for help on using the changeset viewer.