Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/db/dbmi_base/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ char *db_store(const char *s)
{
char *a;

a = db_malloc(strlen(s) + 1);
a = db_malloc((int)strlen(s) + 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    char *a;
    size_t len = strlen(s) + 1;

    if (len > INT_MAX) {
        db_memory_error();
        return NULL;
    }
    a = db_malloc((int)len);

if (a)
strcpy(a, s);
return a;
Expand Down
4 changes: 2 additions & 2 deletions lib/db/dbmi_base/dirent.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ dbDirent *db_dirent(const char *dirname, int *n)
max = 0;
while ((entry = readdir(dp))) {
count++;
len = strlen(entry->d_name);
len = (int)strlen(entry->d_name);
if (len > max)
max = len;
}
rewinddir(dp);

size_t path_len = strlen(dirname) + max + 2; // extra 2 for / and NULL
path = db_malloc(path_len);
path = db_malloc((int)path_len);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len and max can be size_t without a cast, since max only goes into path_len. path_len itself needs the check:

Suggested change
path = db_malloc((int)path_len);
if (path_len > INT_MAX) {
db_memory_error();
closedir(dp);
return (dbDirent *)NULL;
}
path = db_malloc((int)path_len);

if (path == NULL) {
closedir(dp);
return (dbDirent *)NULL;
Expand Down
6 changes: 3 additions & 3 deletions lib/db/dbmi_base/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static int set_string(dbString *x, char *s, int copy)
copy = 1;
}

len = strlen(s) + 1;
len = (int)strlen(s) + 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With size_t len; at the top of set_string():

    len = strlen(s) + 1;

    if (copy) {
        if (len > INT_MAX) {
            db_memory_error();
            return DB_MEMORY_ERR;
        }
        stat = db_enlarge_string(x, (int)len);


if (copy) {
stat = db_enlarge_string(x, len);
Expand Down Expand Up @@ -202,14 +202,14 @@ dbString *db_alloc_string_array(int count)
*/
int db_append_string(dbString *x, const char *s)
{
int len;
size_t len;
int stat;

if (!db_get_string(x))
return db_set_string(x, s);

len = strlen(db_get_string(x)) + strlen(s) + 1;
stat = db_enlarge_string(x, len);
stat = db_enlarge_string(x, (int)len);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stat = db_enlarge_string(x, (int)len);
if (len > INT_MAX) {
db_memory_error();
return DB_MEMORY_ERR;
}
stat = db_enlarge_string(x, (int)len);

if (stat != DB_OK)
return stat;
strcat(db_get_string(x), s);
Expand Down
2 changes: 1 addition & 1 deletion lib/db/dbmi_base/xdrstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int db__send_string(dbString *x)
{
int stat = DB_OK;
const char *s = db_get_string(x);
int len = s ? strlen(s) + 1 : 1;
int len = s ? (int)strlen(s) + 1 : 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sent length stays int, so compute it as size_t and fail like the send errors below:

    size_t size = s ? strlen(s) + 1 : 1;
    int len;

    if (size > INT_MAX) {
        db_protocol_error();
        return DB_PROTOCOL_ERR;
    }
    len = (int)size;


if (!s)
s = ""; /* don't send a NULL string */
Expand Down
Loading