rem: strcpy(upd->filename, buf);
add: memcpy(upd->filename, cp, fnlen); upd->filename[fnlen] = 0;
context: UPDATE * parse_op(char * s){  char buf[1024];  char * p;  UPDATE * upd;  int i;  upd = (UPDATE *)malloc(sizeof(UPDATE));  if (upd == NULL) {    fprintf(stderr, "%s: out of memory\n", progname);    exit(1);  }  i = 0;  p = s;  while ((i < (sizeof(buf)-1) && *p && (*p != ':')))    buf[i++] = *p++;  if (*p != ':') {    fprintf(stderr, "%s: invalid update specification\n", progname);    free(upd);    return NULL;  }  buf[i] = 0;  upd->memtype = (char *)malloc(strlen(buf)+1);  if (upd->memtype == NULL) {    fprintf(stderr, "%s: out of memory\n", progname);    exit(1);  }  strcpy(upd->memtype, buf);  p++;  if (*p == 'r') {    upd->op = DEVICE_READ;  }  else if (*p == 'w') {    upd->op = DEVICE_WRITE;  }  else if (*p == 'v') {    upd->op = DEVICE_VERIFY;  }  else {    fprintf(stderr, "%s: invalid I/O mode '%c' in update specification\n",            progname, *p);    fprintf(stderr,             "  allowed values are:\n"            "    r = read device\n"            "    w = write device\n"            "    v = verify device\n");    free(upd->memtype);    free(upd);    return NULL;  }  p++;  if (*p != ':') {    fprintf(stderr, "%s: invalid update specification\n", progname);    free(upd->memtype);    free(upd);    return NULL;  }  p++;  i = 0;  while ((i < (sizeof(buf)-1) && *p && (*p != ':')))    buf[i++] = *p++;    if (!((*p == ':')||(*p == 0))) {    fprintf(stderr, "%s: invalid update specification\n", progname);    free(upd->memtype);    free(upd);    return NULL;  }  buf[i] = 0;  upd->filename = (char *)malloc(strlen(buf)+1);  if (upd->filename == NULL) {    fprintf(stderr, "%s: out of memory\n", progname);    free(upd->memtype);    free(upd);    return NULL;  }  strcpy(upd->filename, buf);  upd->format = FMT_AUTO;  if (*p == ':') {    p++;    switch (*p) {      case 'a': upd->format = FMT_AUTO; break;      case 's': upd->format = FMT_SREC; break;      case 'i': upd->format = FMT_IHEX; break;      case 'r': upd->format = FMT_RBIN; break;      case 'm': upd->format = FMT_IMM; break;      default:        fprintf(stderr, "%s: invalid file format '%c' in update specifier\n",                progname, *p);        free(upd->memtype);        free(upd->filename);        free(upd);        return NULL;    }    p++;  }  if (*p != 0) {    fprintf(stderr,             "%s: WARNING, extraneous data (%s) in update specifier ignored\n",            progname, p);  }    return upd;}