Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocasazza committed Jul 13, 2016
1 parent 4a1bb9f commit fe81d74
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 11 deletions.
6 changes: 3 additions & 3 deletions include/ulib/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ extern U_EXPORT char u_hostname[HOST_NAME_MAX+1];
extern U_EXPORT const int MultiplyDeBruijnBitPosition2[32];
extern U_EXPORT uint32_t u_hostname_len, u_user_name_len, u_seed_hash;

extern U_EXPORT const unsigned char u_alphabet[]; /* "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" */
extern U_EXPORT const unsigned char u_hex_upper[]; /* "0123456789ABCDEF" */
extern U_EXPORT const unsigned char u_hex_lower[]; /* "0123456789abcdef" */
extern U_EXPORT const unsigned char u_alphabet[64]; /* "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" */
extern U_EXPORT const unsigned char u_hex_upper[16]; /* "0123456789ABCDEF" */
extern U_EXPORT const unsigned char u_hex_lower[16]; /* "0123456789abcdef" */

/* conversion number to string */
extern U_EXPORT const char u_ctn2s[201];
Expand Down
7 changes: 7 additions & 0 deletions include/ulib/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ class U_EXPORT UTimeDate {
return *this;
}

#ifdef U_COMPILER_RVALUE_REFS
UTimeDate& operator=(UTimeDate && d) = default;
# if (!defined(__GNUC__) || GCC_VERSION_NUM > 50300) // GCC has problems dealing with move constructor, so turn the feature on for 5.3.1 and above, only
UTimeDate(UTimeDate && d) = default;
# endif
#endif

// SERVICES

int getJulian()
Expand Down
2 changes: 1 addition & 1 deletion include/ulib/net/server/usp_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#define USP_JSON_PUTS(json) UValue::stringify(*UClientImage_Base::wbuffer, (json))
#define USP_JSON_REQUEST_PARSE(obj) JSON_parse(*UClientImage_Base::body, (obj))
#define USP_JFIND_REQUEST(type,type_len,str) UValue::jfind(*UClientImage_Base::body,(type)i,(type_len),(str))
#define USP_JFIND_REQUEST(type,type_len,str) UValue::jfind(*UClientImage_Base::body,(type),(type_len),(str))
#define USP_JSON_stringify(json,class_name,obj) ((json).toJSON(UJsonTypeHandler<class_name>(obj)), USP_JSON_PUTS(json))

#define USP_XML_PUTS(string) \
Expand Down
14 changes: 14 additions & 0 deletions include/ulib/utility/services.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ struct U_EXPORT UServices {
static void generateDigest(int alg, uint32_t keylen, const UString& data, UString& output, int base64 = 0)
{ generateDigest(alg, keylen, (unsigned char*)U_STRING_TO_PARAM(data), output, base64); }

static UString generateCode(uint32_t len = 6)
{
U_TRACE(0, "UServices::generateCode(%u)", len)

UString code(len);
char* ptr = code.data();

for (uint32_t i = 0; i < len; ++i, ++ptr) *ptr = u_alphabet[u_get_num_random(sizeof(u_alphabet) - 3)];

code.size_adjust(len);

U_RETURN_STRING(code);
}

#ifdef USE_LIBSSL
static UString createToken(int alg = U_HASH_SHA256);

Expand Down
8 changes: 5 additions & 3 deletions src/ulib/base/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ int32_t u_printf_string_max_length;
uint32_t u_hostname_len, u_user_name_len, u_seed_hash = 0xdeadbeef;
const int MultiplyDeBruijnBitPosition2[32] = { 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 };
const char* restrict u_tmpdir = "/tmp";
const unsigned char u_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const unsigned char u_hex_upper[] = "0123456789ABCDEF";
const unsigned char u_hex_lower[] = "0123456789abcdef";
const unsigned char u_hex_upper[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
const unsigned char u_hex_lower[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
const unsigned char u_alphabet[64] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/' };

struct uclientimage_info u_clientimage_info;

Expand Down
7 changes: 5 additions & 2 deletions src/ulib/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,17 @@ U_EXPORT istream& operator>>(istream& is, UCache& cache)
is >> datalen;
is.get(); // skip ':'

# ifndef U_COVERITY_FALSE_POSITIVE /* TAINTED_SCALAR */
is.read(key, keylen);
# endif

U_INTERNAL_DUMP("key = %.*S keylen = %u", keylen, key, keylen)

U_INTERNAL_ASSERT_MINOR(keylen, U_MAX_KEYLEN)

ptr = cache.add(key, keylen, datalen, 0);

// coverity[TAINTED_SCALAR]
# ifndef U_COVERITY_FALSE_POSITIVE
# ifndef U_COVERITY_FALSE_POSITIVE // coverity[TAINTED_SCALAR]
U_MEMCPY(ptr, key, keylen);
# endif

Expand All @@ -454,7 +455,9 @@ U_EXPORT istream& operator>>(istream& is, UCache& cache)

ptr += keylen;

# ifndef U_COVERITY_FALSE_POSITIVE /* TAINTED_SCALAR */
is.read(ptr, datalen);
# endif

U_INTERNAL_DUMP("data = %.*S datalen = %u", datalen, ptr, datalen)

Expand Down
4 changes: 4 additions & 0 deletions src/ulib/db/cdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,9 @@ U_EXPORT istream& operator>>(istream& is, UCDB& cdb)

ptr += sizeof(UCDB::cdb_record_header);

# ifndef U_COVERITY_FALSE_POSITIVE /* TAINTED_SCALAR */
is.read(ptr, klen);
# endif

U_INTERNAL_DUMP("key = %.*S", klen, ptr)

Expand All @@ -962,7 +964,9 @@ U_EXPORT istream& operator>>(istream& is, UCDB& cdb)

ptr += klen;

# ifndef U_COVERITY_FALSE_POSITIVE /* TAINTED_SCALAR */
is.read(ptr, dlen);
# endif

U_INTERNAL_DUMP("data = %.*S", dlen, ptr)

Expand Down
2 changes: 1 addition & 1 deletion src/ulib/utility/services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ UString UServices::createToken(int alg)
{
U_TRACE(0, "UServices::createToken(%d)", alg)

UString output(40U);
UString output(64U);
uint32_t u = u_get_num_random(0);

u_dgst_init(alg, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/ulib/string.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

start_msg string

#UTRACE="0 50M -1"
#UTRACE="0 50M 0"
#UOBJDUMP="0 100k 10"
#USIMERR="error.sim"
UMEMPOOL=0,0,0,0,0,0,0,0,0:20971520,2097152
Expand Down
5 changes: 5 additions & 0 deletions tests/ulib/test_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,11 @@ U_EXPORT main (int argc, char* argv[])
U_ASSERT( UStringExt::compareversion(U_STRING_FROM_CONSTANT("2.1000"), U_STRING_FROM_CONSTANT("3.111")) < 0 )
U_ASSERT( UStringExt::compareversion(U_STRING_FROM_CONSTANT("3.111"), U_STRING_FROM_CONSTANT("2.1000")) > 0 )

#ifdef USE_LIBSSL
z = UServices::createToken();
#endif
z = UServices::generateCode();

/* recursively expand variables if needed
#define ENV_1 \
Expand Down

0 comments on commit fe81d74

Please sign in to comment.