Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > 738a681b5c2e2fed80f2ba9a5506a4b5 > files > 59

OpenOffice.org-1.0.1-9mdk.src.rpm

#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

int main (int argc, char **argv)
{
  struct stat st;
  int fd, changed = 0;
  unsigned char *buf, *p, *q, *lim;
  unsigned char *str = OPENOFFICE_HOME "/program";
  int len = strlen (str), i;

  if (argc != 2)
    exit (1);
  fd = open (argv[1], O_RDWR);
  if (fd < 0)
    exit (2);
  if (fstat (fd, &st) < 0)
    exit (3);
  buf = malloc (st.st_size);
  if (buf == NULL)
    exit (4);
  if (read (fd, buf, st.st_size) != st.st_size)
    exit (5);
  lim = buf + st.st_size;
  for (p = buf; p; p = memchr (p + 1, 'M', lim - p - 1))
    if (strncmp (p, "MOZILLA_FIVE_HOME=/", 19) == 0)
      {
	changed++;
	p += 18;
	q = memchr (p, '\0', lim - p);
	if (q == NULL)
	  exit (6);
	if (q - p < len)
	  exit (7);
	strcpy (p, str);
      }
  if (changed != 1)
    exit (8);
  if (lseek (fd, 0, 0) != 0)
    exit (9);
  if (write (fd, buf, st.st_size) != st.st_size)
    exit (10);
  exit (0);
}