Skip to contentSkip to conversation

xl: use xstrdup in cpurange_parse

PATCH In review Wei Liu 3 participants 5 messages May 25, 2016

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 xl: use xstrdup in cpurange_parse

This ensures buf is always valid when it is passed to strtok_r.

CID: 1291936

---
Cc: Ian Jackson <[email protected]>

This is a backport candidate.

---
 tools/libxl/xl_cmdimpl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/xl_cmdimpl.c +1 -1
index 03ab644..d8530f0 100644
@@ -847,7 +847,7 @@ static int update_cpumap_range(const char *str, libxl_bitmap *cpumap)
  */
 static int cpurange_parse(const char *cpu, libxl_bitmap *cpumap)
 {
-    char *ptr, *saveptr = NULL, *buf = strdup(cpu);
+    char *ptr, *saveptr = NULL, *buf = xstrdup(cpu);
     int rc = 0;
 
     for (ptr = strtok_r(buf, ",", &saveptr); ptr;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 1/1
#2 lore raw
In reply to Wei Liu

Wei Liu writes ("[PATCH for-4.7] xl: use xstrdup in cpurange_parse"):

Quoted 5 lines

This ensures buf is always valid when it is passed to strtok_r.

CID: 1291936

Quoted 1 line

This is a backport candidate.

Really ? malloc failing is vanishingly rare in practice nowadays and the consequence is a crash (which is what xstrdup achieves anyway).

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#3 lore raw
Quoted 5 lines · Ian Jackson

Wei Liu writes ("[PATCH for-4.7] xl: use xstrdup in cpurange_parse"):

Quoted 4 lines

This ensures buf is always valid when it is passed to strtok_r.

CID: 1291936

Quoted 9 lines
Quoted 1 line
Quoted 1 line

This is a backport candidate.

Really ? malloc failing is vanishingly rare in practice nowadays and the consequence is a crash (which is what xstrdup achieves anyway).

This is a fair argument. I will leave the judgement to you. If you don't think this is worth backporting I won't insist. :-)

Quoted 1 line

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel