Skip to contentSkip to conversation

xfs_restore: Fix compile warnings with strncpy size equal to string size

PATCH In review Frank Sorenson 2 participants 2 messages Dec 13, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_restore: Fix compile warnings with strncpy size equal to string size

If the strncpy size equals the string size, the result will not be null-terminated.

Call the already-existing strncpyterm which ensures proper termination.

---
 restore/content.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
restore/content.c +4 -4
index 5e30f08..4c4d6ec 100644
@@ -5081,7 +5081,7 @@ pi_insertfile(ix_t drivecnt,
 	     &&
 	     ! DH2O(objh)->o_idlabvalpr) {
 		uuid_copy(DH2O(objh)->o_id, *mediaidp);
-		strncpy(DH2O(objh)->o_lab,
+		strncpyterm(DH2O(objh)->o_lab,
 			 medialabel,
 			 sizeof(DH2O(objh)->o_lab));
 		DH2O(objh)->o_idlabvalpr = BOOL_TRUE;
@@ -5111,7 +5111,7 @@ pi_insertfile(ix_t drivecnt,
 	     &&
 	     ! DH2O(prevobjh)->o_idlabvalpr) {
 		uuid_copy(DH2O(prevobjh)->o_id, *prevmediaidp);
-		strncpy(DH2O(prevobjh)->o_lab,
+		strncpyterm(DH2O(prevobjh)->o_lab,
 			       prevmedialabel,
 			       sizeof(DH2O(prevobjh)->o_lab));
 		DH2O(prevobjh)->o_idlabvalpr = BOOL_TRUE;
@@ -5581,7 +5581,7 @@ pi_transcribe(inv_session_t *sessp)
 					       fileszvalpr,
 					       filep->m_size);
 			uuid_copy(lastobjid, filep->m_moid);
-			strncpy(lastobjlabel,
+			strncpyterm(lastobjlabel,
 				 filep->m_label,
 				 sizeof(lastobjlabel));
 			dumpmediafileix++;
@@ -6749,7 +6749,7 @@ addobj(bag_t *bagp,
 	bagobjp = (bagobj_t *)calloc(1, sizeof(bagobj_t));
 	assert(bagobjp);
 	uuid_copy(bagobjp->id, *idp);
-	strncpy(bagobjp->label,
+	strncpyterm(bagobjp->label,
 		 label,
 		 sizeof(bagobjp->label));
 	bagobjp->indrivepr = indrivepr;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Frank Sorenson

If the strncpy size equals the string size, the result will not be null-terminated.

Call the already-existing strncpyterm which ensures proper termination.

Thanks Frank!

Quoted 45 lines
---
 restore/content.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
restore/content.c +4 -4
index 5e30f08..4c4d6ec 100644
@@ -5081,7 +5081,7 @@ pi_insertfile(ix_t drivecnt,
 	     &&
 	     ! DH2O(objh)->o_idlabvalpr) {
 		uuid_copy(DH2O(objh)->o_id, *mediaidp);
-		strncpy(DH2O(objh)->o_lab,
+		strncpyterm(DH2O(objh)->o_lab,
 			 medialabel,
 			 sizeof(DH2O(objh)->o_lab));
 		DH2O(objh)->o_idlabvalpr = BOOL_TRUE;
@@ -5111,7 +5111,7 @@ pi_insertfile(ix_t drivecnt,
 	     &&
 	     ! DH2O(prevobjh)->o_idlabvalpr) {
 		uuid_copy(DH2O(prevobjh)->o_id, *prevmediaidp);
-		strncpy(DH2O(prevobjh)->o_lab,
+		strncpyterm(DH2O(prevobjh)->o_lab,
 			       prevmedialabel,
 			       sizeof(DH2O(prevobjh)->o_lab));
 		DH2O(prevobjh)->o_idlabvalpr = BOOL_TRUE;
@@ -5581,7 +5581,7 @@ pi_transcribe(inv_session_t *sessp)
 					       fileszvalpr,
 					       filep->m_size);
 			uuid_copy(lastobjid, filep->m_moid);
-			strncpy(lastobjlabel,
+			strncpyterm(lastobjlabel,
 				 filep->m_label,
 				 sizeof(lastobjlabel));
 			dumpmediafileix++;
@@ -6749,7 +6749,7 @@ addobj(bag_t *bagp,
 	bagobjp = (bagobj_t *)calloc(1, sizeof(bagobj_t));
 	assert(bagobjp);
 	uuid_copy(bagobjp->id, *idp);
-	strncpy(bagobjp->label,
+	strncpyterm(bagobjp->label,
 		 label,
 		 sizeof(bagobjp->label));
 	bagobjp->indrivepr = indrivepr;