Skip to content

Commit

Permalink
Merge pull request #60 from ppadmavilasom/dev
Browse files Browse the repository at this point in the history
update to 1.0.8, add string allocation limits
  • Loading branch information
ppadmavilasom committed Apr 1, 2016
2 parents c052e27 + b3b6325 commit 05877b3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ typedef enum
#define TDNF_CONF_KEY_KEEP_CACHE "keepcache"
#define TDNF_CONF_KEY_DISTROVERPKG "distroverpkg"
#define TDNF_CONF_KEY_DISTROARCHPKG "distroarchpkg"
#define TDNF_CONF_KEY_MAX_STRING_LEN "maxstringlen"
//Repo file key names
#define TDNF_REPO_KEY_BASEURL "baseurl"
#define TDNF_REPO_KEY_ENABLED "enabled"
Expand All @@ -133,6 +134,7 @@ typedef enum
#define TDNF_DEFAULT_CACHE_LOCATION "/var/cache/tdnf"
#define TDNF_DEFAULT_DISTROVERPKG "photon-release"
#define TDNF_DEFAULT_DISTROARCHPKG "x86_64"
#define TDNF_DEFAULT_MAX_STRING_LEN 16384000
#define TDNF_RPM_CACHE_DIR_NAME "rpms"
#define TDNF_REPODATA_DIR_NAME "repodata"
//var names
Expand All @@ -154,6 +156,7 @@ typedef enum
{ERROR_TDNF_NO_DISTROVERPKG, "ERROR_TDNF_NO_DISTROVERPKG", "distroverpkg config entry is set to a package that is not installed. Check /etc/tdnf/tdnf.conf"}, \
{ERROR_TDNF_DISTROVERPKG_READ, "ERROR_TDNF_DISTROVERPKG_READ", "There was an error reading version of distroverpkg"}, \
{ERROR_TDNF_INVALID_ALLOCSIZE, "ERROR_TDNF_INVALID_ALLOCSIZE", "A memory allocation was requested with an invalid size"}, \
{ERROR_TDNF_STRING_TOO_LONG, "ERROR_TDNF_STRING_TOO_LONG", "Requested string allocation size was too long."}, \
{ERROR_TDNF_NO_ENABLED_REPOS, "ERROR_TDNF_NO_ENABLED_REPOS", "There are no enabled repos.\n Run ""tdnf repolist all"" to see the repos you have.\n You can enable repos by editing repo files in your repodir(usually /etc/yum.repos.d)"}, \
{ERROR_TDNF_PACKAGELIST_EMPTY, "ERROR_TDNF_PACKAGELIST_EMPTY", "Packagelist was empty"}, \
{ERROR_TDNF_GOAL_CREATE, "ERROR_TDNF_GOAL_CREATE", "Error creating goal"}, \
Expand Down
14 changes: 13 additions & 1 deletion client/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ TDNFAllocateString(
BAIL_ON_TDNF_ERROR(dwError);
}

if(strlen(pszSrc) > TDNF_DEFAULT_MAX_STRING_LEN)
{
dwError = ERROR_TDNF_STRING_TOO_LONG;
BAIL_ON_TDNF_ERROR(dwError);
}

pszDst = strdup(pszSrc);
if(!pszDst)
{
Expand Down Expand Up @@ -111,8 +117,14 @@ TDNFAllocateStringPrintf(
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

nSize = nSize + 1;

if(nSize > TDNF_DEFAULT_MAX_STRING_LEN)
{
dwError = ERROR_TDNF_STRING_TOO_LONG;
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = TDNFAllocateMemory(1, nSize, (void**)&pszDst);
BAIL_ON_TDNF_ERROR(dwError);

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT(tdnf, 1.0.7)
AC_INIT(tdnf, 1.0.8)
AC_MSG_NOTICE([tdnf configuration])

AC_CANONICAL_SYSTEM
Expand Down
1 change: 1 addition & 0 deletions include/tdnferror.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ extern "C" {
#define ERROR_TDNF_DISTROVERPKG_READ 1023
//
#define ERROR_TDNF_INVALID_ALLOCSIZE 1024
#define ERROR_TDNF_STRING_TOO_LONG 1025

//Hawkey errors 1300 to 1399
#define ERROR_TDNF_HAWKEY_BASE 1300
Expand Down

0 comments on commit 05877b3

Please sign in to comment.