From bf1cbdd8389d5e7067b03c1f10e9fbcb3756ccf4 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 6 Apr 2009 18:16:04 +0000 Subject: [PATCH] contrib/lar: fix buffer overflow check, define os dir seperator --- contrib/lar/lar.c | 6 +++--- contrib/lar/lar.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/contrib/lar/lar.c b/contrib/lar/lar.c index ad6cfc8e5..839b29299 100644 --- a/contrib/lar/lar.c +++ b/contrib/lar/lar.c @@ -183,7 +183,7 @@ lar_archive * lar_find_archive( const char *package ) for( len = 0; package[len] != '\0'; len++ ) { - if( len >= sizeof(buffer) ) + if( len >= (sizeof(buffer) - 5) ) LAR_DIE("Package name exceeds maximum allowed length"); if( package[len] == '.' ) seg++; @@ -197,7 +197,7 @@ lar_archive * lar_find_archive( const char *package ) if( j < seg ) j++; else break; } - buffer[i] = ( package[i] == '.' ) ? '/' : package[i]; + buffer[i] = ( package[i] == '.' ) ? LAR_DIRSEP : package[i]; } buffer[i+0] = '.'; buffer[i+1] = 'l'; buffer[i+2] = 'a'; @@ -219,7 +219,7 @@ lar_member * lar_find_member( lar_archive *ar, const char *package ) for( len = 0; package[len] != '\0'; len++ ) { - if( len >= sizeof(buffer) ) + if( len >= (sizeof(buffer) - 5) ) LAR_DIE("Package name exceeds maximum allowed length"); buffer[len] = ( package[len] == '.' ) ? '/' : package[len]; diff --git a/contrib/lar/lar.h b/contrib/lar/lar.h index c5b429b9f..59e6fa620 100644 --- a/contrib/lar/lar.h +++ b/contrib/lar/lar.h @@ -1,3 +1,6 @@ +#ifndef __LAR_H +#define __LAR_H + #include #include #include @@ -25,6 +28,12 @@ int errno; #define LAR_FNAME_BUFFER 1024 #define LAR_FNAME(s) char s[LAR_FNAME_BUFFER] +#ifdef __WIN32__ +#define LAR_DIRSEP '\\' +#else +#define LAR_DIRSEP '/' +#endif + struct lar_index_item { uint32_t noffset; @@ -76,3 +85,6 @@ int lar_close( lar_archive *ar ); lar_archive * lar_find_archive( const char *package ); lar_member * lar_find_member( lar_archive *ar, const char *package ); + +#endif + -- 2.25.1