Avoid a NULL dereference when listing an NTFS partition after RebuildBS

This commit is contained in:
Christophe Grenier 2018-02-07 18:12:38 +01:00
parent e1d86c408e
commit 78380d72f7
12 changed files with 24 additions and 7 deletions

View file

@ -6,7 +6,7 @@ AC_INIT([testdisk],[7.1-WIP],[grenier@cgsecurity.org])
AC_LANG(C)
sinclude(acx_pthread.m4)
sinclude(mkdir.m4)
TESTDISKDATE="November 2017"
TESTDISKDATE="February 2018"
AC_SUBST(TESTDISKDATE)
AC_DEFINE_UNQUOTED([TESTDISKDATE],"$TESTDISKDATE",[Date of release])
AC_CONFIG_AUX_DIR(config)

View file

@ -215,6 +215,7 @@ static int adv_string_to_command(char**current_cmd, list_part_t **current_elemen
{
int keep_asking;
int command='q';
assert(current_cmd!=NULL);
do
{
keep_asking=0;
@ -474,6 +475,7 @@ void interface_adv(disk_t *disk_car, const int verbose,const int dump_ind, const
unsigned int menu=0;
list_part_t *list_part;
list_part_t *current_element;
assert(current_cmd!=NULL);
log_info("\nInterface Advanced\n");
list_part=disk_car->arch->read_part(disk_car,verbose,0);
current_element=list_part;

View file

@ -27,6 +27,7 @@
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <assert.h>
#include "types.h"
#include "common.h"
#include "chgtype.h"
@ -38,6 +39,8 @@ extern const arch_fnct_t arch_none;
void change_part_type_cli(const disk_t *disk_car,partition_t *partition, char **current_cmd)
{
assert(current_cmd!=NULL);
assert(partition!=NULL);
if(*current_cmd==NULL || partition->arch==NULL)
return ;
if(partition->arch==NULL)

View file

@ -596,7 +596,7 @@ static int dir_partition_aux(disk_t *disk, const partition_t *partition, dir_dat
inode_known[depth]=inode;
dir_data->get_dir(disk, partition, dir_data, inode, &dir_list);
dir_aff_log(dir_data, &dir_list);
if(*current_cmd!=NULL)
if(current_cmd!=NULL && *current_cmd!=NULL)
{
/* TODO: handle copy_files */
dir_data->current_directory[current_directory_namelength]='\0';

View file

@ -122,7 +122,7 @@ dir_partition_t dir_partition(disk_t *disk, const partition_t *partition, const
log_partition(disk,partition);
screen_buffer_add("Support for this filesystem hasn't been implemented.\n");
screen_buffer_to_log();
if(*current_cmd==NULL)
if(current_cmd==NULL || *current_cmd==NULL)
{
#ifdef HAVE_NCURSES
screen_buffer_display(window,"",NULL);
@ -139,7 +139,7 @@ dir_partition_t dir_partition(disk_t *disk, const partition_t *partition, const
log_partition(disk,partition);
screen_buffer_add("Support for this filesystem wasn't enabled during compilation.\n");
screen_buffer_to_log();
if(*current_cmd==NULL)
if(current_cmd==NULL || *current_cmd==NULL)
{
#ifdef HAVE_NCURSES
screen_buffer_display(window,"",NULL);
@ -156,7 +156,7 @@ dir_partition_t dir_partition(disk_t *disk, const partition_t *partition, const
log_partition(disk,partition);
screen_buffer_add("Can't open filesystem. Filesystem seems damaged.\n");
screen_buffer_to_log();
if(*current_cmd==NULL)
if(current_cmd==NULL || *current_cmd==NULL)
{
#ifdef HAVE_NCURSES
screen_buffer_display(window,"",NULL);
@ -167,7 +167,7 @@ dir_partition_t dir_partition(disk_t *disk, const partition_t *partition, const
{
int recursive=0;
int copy_files=0;
if(*current_cmd!=NULL)
if(current_cmd!=NULL && *current_cmd!=NULL)
{
int do_continue;
do

View file

@ -66,7 +66,7 @@ static void dump_fat1x(disk_t *disk_car, partition_t *partition, const unsigned
{
log_info("Boot sector\n");
dump_log(buffer_bs, FAT1x_BOOT_SECTOR_SIZE);
if(*current_cmd==NULL)
if(current_cmd==NULL || *current_cmd==NULL)
{
#ifdef HAVE_NCURSES
dump_fat1x_ncurses(disk_car, partition, buffer_bs);

View file

@ -42,6 +42,7 @@
#if defined(HAVE_SYS_UUID_H)
#include <sys/uuid.h>
#endif
#include <assert.h>
#include "common.h"
#include "fnctdsk.h"
#include "lang.h"
@ -335,6 +336,7 @@ static list_part_t *init_part_order_gpt(const disk_t *disk_car, list_part_t *lis
list_part_t *add_partition_gpt_cli(disk_t *disk_car,list_part_t *list_part, char **current_cmd)
{
assert(current_cmd!=NULL);
partition_t *new_partition=partition_new(&arch_gpt);
new_partition->part_offset=disk_car->sector_size;
new_partition->part_size=disk_car->disk_size-new_partition->part_offset;

View file

@ -33,6 +33,7 @@
#include <string.h>
#endif
#include <ctype.h> /* tolower */
#include <assert.h>
#include "types.h"
#include "common.h"
#include "fnctdsk.h"
@ -186,6 +187,7 @@ list_part_t *add_partition_humax_cli(disk_t *disk_car,list_part_t *list_part, ch
{
CHS_t start,end;
partition_t *new_partition=partition_new(&arch_humax);
assert(current_cmd!=NULL);
start.cylinder=0;
start.head=0;
start.sector=1;

View file

@ -33,6 +33,7 @@
#include <string.h>
#endif
#include <ctype.h> /* tolower */
#include <assert.h>
#include "types.h"
#include "common.h"
#include "fnctdsk.h"
@ -1222,6 +1223,7 @@ list_part_t *add_partition_i386_cli(disk_t *disk_car, list_part_t *list_part, ch
{
CHS_t start,end;
partition_t *new_partition=partition_new(&arch_i386);
assert(current_cmd!=NULL);
start.cylinder=0;
start.head=0;
start.sector=1;

View file

@ -33,6 +33,7 @@
#include <string.h>
#endif
#include <ctype.h> /* tolower */
#include <assert.h>
#include "types.h"
#include "common.h"
#include "fnctdsk.h"
@ -212,6 +213,7 @@ static list_part_t *init_part_order_mac(const disk_t *disk_car, list_part_t *lis
list_part_t *add_partition_mac_cli(disk_t *disk_car,list_part_t *list_part, char **current_cmd)
{
partition_t *new_partition=partition_new(&arch_mac);
assert(current_cmd!=NULL);
new_partition->part_offset=disk_car->sector_size;
new_partition->part_size=disk_car->disk_size-disk_car->sector_size;
while(*current_cmd[0]==',')

View file

@ -33,6 +33,7 @@
#include <string.h>
#endif
#include <ctype.h> /* tolower */
#include <assert.h>
#include "types.h"
#include "common.h"
#include "fnctdsk.h"
@ -218,6 +219,7 @@ static list_part_t *init_part_order_sun(const disk_t *disk_car, list_part_t *lis
list_part_t *add_partition_sun_cli(disk_t *disk_car,list_part_t *list_part, char **current_cmd)
{
CHS_t start,end;
assert(current_cmd!=NULL);
partition_t *new_partition=partition_new(&arch_sun);
start.cylinder=0;
start.head=0;

View file

@ -33,6 +33,7 @@
#include <string.h>
#endif
#include <ctype.h> /* tolower */
#include <assert.h>
#include "types.h"
#include "common.h"
#include "fnctdsk.h"
@ -147,6 +148,7 @@ static list_part_t *init_part_order_xbox(const disk_t *disk_car, list_part_t *li
list_part_t *add_partition_xbox_cli(disk_t *disk_car,list_part_t *list_part, char **current_cmd)
{
partition_t *new_partition=partition_new(&arch_xbox);
assert(current_cmd!=NULL);
new_partition->part_offset=disk_car->sector_size;
new_partition->part_size=disk_car->disk_size-disk_car->sector_size;
while(*current_cmd[0]==',')