diff --git a/CMakeLists.txt b/CMakeLists.txt index dd9ea5b..da37c15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8.15) +cmake_minimum_required(VERSION 3.10) project(mars_nwe) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) diff --git a/src/nwdbm.c b/src/nwdbm.c index 760edd5..51b8fc2 100644 --- a/src/nwdbm.c +++ b/src/nwdbm.c @@ -559,7 +559,9 @@ int nw_rename_obj(NETOBJ *o, uint8 *newname) if (data.dptr != NULL){ NETOBJ *obj=(NETOBJ*)data.dptr; XDPRINTF((2,0, "rename_obj:got OBJ name=%s, id = 0x%x", obj->name, (int)obj->id)); - strncpy(obj->name, newname, 48); + memset(obj->name, 0, sizeof(obj->name)); + strncpy((char*)obj->name, (char*)newname, sizeof(obj->name)-1); + obj->name[sizeof(obj->name)-1] = '\0'; if (!store(key, data)) { memcpy(o, obj, sizeof(NETOBJ)); /* for handle_iobj */ result=0; @@ -777,7 +779,6 @@ static int prop_add_member(uint32 obj_id, int prop_id, int prop_security, U32_TO_BE32(member_id, p); memcpy(&val, v, sizeof(NETVAL)); data.dptr = (char*)&val; - key.dptr = (char*)&val; if (store(key, data)) result=-0xff; goto L1; } else p += 4; @@ -845,7 +846,7 @@ int nw_get_prop_val_by_obj_id(uint32 obj_id, { NETPROP prop; int result=-0xff; - strmaxcpy((char*)prop.name, (char*)prop_name, prop_namlen); + strmaxcpy(prop.name, prop_name, prop_namlen); XDPRINTF((5,0, "nw_get_prop_val_by_obj_id,id=0x%x, prop=%s, segment=%d", obj_id, prop.name, segment_nr)); @@ -1479,7 +1480,7 @@ static int nw_update_oldpasswd(uint32 obj_id, char *pwd) if (memcmp(pwd,segm+segment*16,16)==0)return 1; } // Update record - memcpy(segm+16,segm,128-16); + memmove(segm+16, segm, 128-16); memcpy(segm,pwd,16); nw_new_obj_prop(obj_id, NULL, 0, 0, 0, @@ -1770,10 +1771,10 @@ static void create_nw_db(char *fn, int always) char fna[300]; (void)get_div_pathes(pa, "nwdbm.sav", 1, NULL); nwdbm_mkdir(pa, 0700, 0); - sprintf(fna, "%s/%s.dir", pa, fn); + snprintf(fna, sizeof(fna), "%s/%s.dir", pa, fn); unlink(fna); rename(fname, fna); - sprintf(fna, "%s/%s.pag", pa, fn); + snprintf(fna, sizeof(fna), "%s/%s.pag", pa, fn); unlink(fna); (void)get_div_pathes(pa, fn, 1, ".pag"); rename(pa, fna);