Skip to content

Commit 16dba04

Browse files
committed
8332589: ubsan: unix/native/libjava/ProcessImpl_md.c:562:5: runtime error: null pointer passed as argument 2, which is declared to never be null
Reviewed-by: rriggs, mdoerr
1 parent 4e8deb3 commit 16dba04

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/java.base/unix/native/libjava/ProcessImpl_md.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -559,8 +559,17 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
559559
}
560560
offset = copystrings(buf, 0, &c->argv[0]);
561561
offset = copystrings(buf, offset, &c->envv[0]);
562-
memcpy(buf+offset, c->pdir, sp.dirlen);
563-
offset += sp.dirlen;
562+
if (c->pdir != NULL) {
563+
if (sp.dirlen > 0) {
564+
memcpy(buf+offset, c->pdir, sp.dirlen);
565+
offset += sp.dirlen;
566+
}
567+
} else {
568+
if (sp.dirlen > 0) {
569+
free(buf);
570+
return -1;
571+
}
572+
}
564573
offset = copystrings(buf, offset, parentPathv);
565574
assert(offset == bufsize);
566575

0 commit comments

Comments
 (0)