Changeset 143 for trunk


Ignore:
Timestamp:
02/12/09 22:24:27 (16 years ago)
Author:
tim
Message:

fixed a null pointer exception

removed some dependencies on less portable items

altered Makefiles to allow for MinGW cross compiling

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r141 r143  
    1515INC=-I/usr/local/include
    1616LIB=-L/usr/local/lib -lm
     17BIN_EXT=
     18EXTRA_OBJ=
    1719
    1820UNAME := $(shell uname)
    1921ifneq ($(UNAME),Linux) 
    2022  LIB:=$(LIB) -liconv
     23endif
     24
     25ifdef BUILD_MINGW
     26CC=i586-mingw32msvc-cc
     27BIN_EXT=.exe
     28LIBICONV_PATH=/usr/local/src/libiconv-1.9.2-1-lib
     29INC:=$(INC) -I$(LIBICONV_PATH)/include
     30EXTRA_OBJ=$(LIBICONV_PATH)/lib/libiconv.dll.a
    2131endif
    2232
  • trunk/include/regfi.h

    r140 r143  
    5858#define REGFI_MSG_WARN  0x0004
    5959#define REGFI_MSG_ERROR 0x0010
     60
     61/* Windows is lame */
     62#ifdef O_BINARY
     63#define REGFI_OPEN_FLAGS O_RDONLY|O_BINARY
     64#else
     65#define REGFI_OPEN_FLAGS O_RDONLY
     66#endif
    6067
    6168/* Registry data types */
  • trunk/lib/regfi.c

    r140 r143  
    510510  ret_val = regfi_load_subkeylist_aux(file, offset, max_size, strict,
    511511                                      REGFI_MAX_SUBKEY_DEPTH);
     512  if(ret_val == NULL)
     513  {
     514    regfi_add_message(file, REGFI_MSG_WARN, "Failed to load subkey list at"
     515                      " offset 0x%.8X.", offset);
     516    return NULL;
     517  }
    512518
    513519  if(num_keys != ret_val->num_keys)
     
    11521158
    11531159  /* open an existing file */
    1154   if ((fd = open(filename, O_RDONLY)) == -1)
    1155   {
    1156     /* DEBUG(0,("regfi_open: failure to open %s (%s)\n", filename, strerror(errno)));*/
     1160  if ((fd = open(filename, REGFI_OPEN_FLAGS)) == -1)
     1161  {
     1162    /* fprintf(stderr, "regfi_open: failure to open %s (%s)\n", filename, strerror(errno));*/
    11571163    return NULL;
    11581164  }
     
    11701176  if ((rb = regfi_parse_regf(fd, true)) == NULL)
    11711177  {
    1172     /* DEBUG(0,("regfi_open: Failed to read initial REGF block\n"));*/
     1178    /* fprintf(stderr, "regfi_open: Failed to read initial REGF block\n"); */
    11731179    close(fd);
    11741180    return NULL;
     
    11791185  if(rb->hbins == NULL)
    11801186  {
     1187    /* fprintf(stderr, "regfi_open: Failed to create HBIN list.\n"); */
    11811188    range_list_free(rb->hbins);
    11821189    close(fd);
     
    13311338   * caching and make things slow.
    13321339   */
    1333   ret_val->sk_recs = lru_cache_create(127, 0x15DEAD05^time(NULL)
    1334                                            ^(getpid()<<16)^(getppid()<<8),
     1340  ret_val->sk_recs = lru_cache_create(127, 0x15DEAD05^time(NULL)^(getpid()<<16),
    13351341                                      true);
    13361342
  • trunk/src/Makefile

    r110 r143  
    33################################################################################
    44
    5 REGLOOKUP=$(BUILD_BIN)/reglookup
    6 REGLOOKUP_RECOVER=$(BUILD_BIN)/reglookup-recover
     5REGLOOKUP=$(BUILD_BIN)/reglookup$(BIN_EXT)
     6REGLOOKUP_RECOVER=$(BUILD_BIN)/reglookup-recover$(BIN_EXT)
    77OBJ=$(wildcard ../lib/*.o)
    88FILES=$(REGLOOKUP) $(REGLOOKUP_RECOVER)
     
    1111
    1212$(REGLOOKUP): reglookup.o $(OBJ)
    13         $(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup.o $(OBJ)
     13        $(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup.o $(OBJ) $(EXTRA_OBJ)
    1414
    1515$(REGLOOKUP_RECOVER): reglookup-recover.o $(OBJ)
    16         $(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup-recover.o $(OBJ)
     16        $(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup-recover.o $(OBJ) $(EXTRA_OBJ)
    1717
    1818reglookup.o: reglookup.c
  • trunk/src/common.c

    r138 r143  
    3131#define REGLOOKUP_VERSION "0.10.0"
    3232
     33#define REGLOOKUP_EXIT_OK       0
     34#define REGLOOKUP_EXIT_OSERR   71
     35#define REGLOOKUP_EXIT_USAGE   64
     36#define REGLOOKUP_EXIT_DATAERR 65
     37#define REGLOOKUP_EXIT_NOINPUT 66
     38
    3339
    3440void bailOut(int code, char* message)
  • trunk/src/reglookup-recover.c

    r138 r143  
    2222#include <stdio.h>
    2323#include <stdlib.h>
    24 #include <sysexits.h>
    2524
    2625#include "../include/regfi.h"
     
    8483    quoted_name = malloc(1*sizeof(char));
    8584    if(quoted_name == NULL)
    86       bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     85      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
    8786    quoted_name[0] = '\0';
    8887
     
    140139    quoted_name = malloc(1*sizeof(char));
    141140    if(quoted_name == NULL)
    142       bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     141      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
    143142    quoted_name[0] = '\0';
    144143  }
     
    149148    quoted_value = malloc(1*sizeof(char));
    150149    if(quoted_value == NULL)
    151       bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     150      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
    152151    quoted_value[0] = '\0';
    153152
     
    714713  {
    715714    usage();
    716     bailOut(EX_USAGE, "ERROR: Requires at least one argument.\n");
     715    bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: Requires at least one argument.\n");
    717716  }
    718717 
     
    738737      usage();
    739738      fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]);
    740       bailOut(EX_USAGE, "");
     739      bailOut(REGLOOKUP_EXIT_USAGE, "");
    741740    }
    742741  }
     
    744743
    745744  if((registry_file = strdup(argv[argi])) == NULL)
    746     bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
     745    bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
    747746
    748747  f = regfi_open(registry_file);
     
    750749  {
    751750    fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file);
    752     bailOut(EX_NOINPUT, "");
     751    bailOut(REGLOOKUP_EXIT_NOINPUT, "");
    753752  }
    754753  if(print_verbose)
  • trunk/src/reglookup.c

    r141 r143  
    2323
    2424#include <stdlib.h>
    25 #include <sysexits.h>
    2625#include <stdio.h>
    2726#include <string.h>
     
    8281    quoted_name = malloc(1*sizeof(char));
    8382    if(quoted_name == NULL)
    84       bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     83      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
    8584    quoted_name[0] = '\0';
    8685  }
     
    161160      copy = (char*)malloc((next-cur+1)*sizeof(char));
    162161      if(copy == NULL)
    163         bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
     162        bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
    164163         
    165164      memcpy(copy, cur, next-cur);
     
    169168        ret_val[ret_cur] = NULL;
    170169      else
    171         bailOut(EX_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
     170        bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
    172171    }
    173172    cur = next+1;
     
    182181      ret_val[ret_cur] = NULL;
    183182    else
    184       bailOut(EX_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
     183      bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
    185184  }
    186185
     
    384383
    385384  if(root == NULL)
    386     bailOut(EX_DATAERR, "ERROR: root cannot be NULL.\n");
     385    bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: root cannot be NULL.\n");
    387386 
    388387  do
     
    392391      path = iter2Path(iter);
    393392      if(path == NULL)
    394         bailOut(EX_OSERR, "ERROR: Could not construct iterator's path.\n");
     393        bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not construct iterator's path.\n");
    395394
    396395      if(!type_filter_enabled || (key_type == type_filter))
     
    410409        {
    411410          printMsgs(iter->f);
    412           bailOut(EX_DATAERR, "ERROR: could not traverse iterator upward.\n");
     411          bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: could not traverse iterator upward.\n");
    413412        }
    414413
     
    417416        {
    418417          printMsgs(iter->f);
    419           bailOut(EX_DATAERR, "ERROR: unexpected NULL for key.\n");
     418          bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n");
    420419        }
    421420
     
    431430      {
    432431        printMsgs(iter->f);
    433         bailOut(EX_DATAERR, "ERROR: could not traverse iterator downward.\n");
     432        bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: could not traverse iterator downward.\n");
    434433      }
    435434
     
    507506
    508507    if((value == NULL) || (tmp_path_joined == NULL))
    509       bailOut(EX_OSERR, "ERROR: Unexpected error before printValue.\n");
     508      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Unexpected error before printValue.\n");
    510509
    511510    if(!type_filter_enabled || (value->type == type_filter))
     
    525524    {
    526525      printMsgs(iter->f);
    527       bailOut(EX_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
     526      bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
    528527    }
    529528
     
    568567  {
    569568    usage();
    570     bailOut(EX_USAGE, "ERROR: Requires at least one argument.\n");
     569    bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: Requires at least one argument.\n");
    571570  }
    572571 
     
    579578      {
    580579        usage();
    581         bailOut(EX_USAGE, "ERROR: '-p' option requires parameter.\n");
     580        bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: '-p' option requires parameter.\n");
    582581      }
    583582      if((path_filter = strdup(argv[argi])) == NULL)
    584         bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
     583        bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
    585584
    586585      path_filter_enabled = true;
     
    591590      {
    592591        usage();
    593         bailOut(EX_USAGE, "ERROR: '-t' option requires parameter.\n");
     592        bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: '-t' option requires parameter.\n");
    594593      }
    595594      if((type_filter = regfi_type_str2val(argv[argi])) < 0)
    596595      {
    597596        fprintf(stderr, "ERROR: Invalid type specified: %s.\n", argv[argi]);
    598         bailOut(EX_USAGE, "");
     597        bailOut(REGLOOKUP_EXIT_USAGE, "");
    599598      }
    600599      type_filter_enabled = true;
     
    614613      usage();
    615614      fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]);
    616       bailOut(EX_USAGE, "");
     615      bailOut(REGLOOKUP_EXIT_USAGE, "");
    617616    }
    618617  }
    619618  if((registry_file = strdup(argv[argi])) == NULL)
    620     bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
     619    bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
    621620
    622621  f = regfi_open(registry_file);
     
    624623  {
    625624    fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file);
    626     bailOut(EX_NOINPUT, "");
     625    bailOut(REGLOOKUP_EXIT_NOINPUT, "");
    627626  }
    628627
     
    632631  iter = regfi_iterator_new(f);
    633632  if(iter == NULL)
    634     bailOut(EX_OSERR, "ERROR: Couldn't create registry iterator.\n");
     633    bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Couldn't create registry iterator.\n");
    635634
    636635  if(print_header)
     
    659658      fprintf(stderr, "ERROR: retrievePath() returned %d.\n",
    660659              retr_path_ret);
    661       bailOut(EX_DATAERR,"ERROR: Unknown error occurred in retrieving path.\n");
     660      bailOut(REGLOOKUP_EXIT_DATAERR,
     661              "ERROR: Unknown error occurred in retrieving path.\n");
    662662    }
    663663  }
Note: See TracChangeset for help on using the changeset viewer.